class 39 - 검색 / 파일업로드

yoneeki·2023년 3월 29일
0

training-jp

목록 보기
29/31

검색 기능

마이바티스

<sql id="search">
    <if test="category != null and searchTxt!=''">
      <choose>
        <when test="category=='all'">
            WHERE 
              (subject LIKE '%' || #{searchTxt} || '%') OR
              (writer LIKE '%' || #{searchTxt} || '%') OR
              (contents LIKE '%' || #{searchTxt} || '%') 
        </when>
        <when test="category=='subject'">
            WHERE 
              (subject LIKE '%' || #{searchTxt} || '%') 
        </when>
        <when test="category=='writer'">
            WHERE 
              (writer LIKE '%' || #{searchTxt} || '%') 
        </when>
        <when test="category=='contents'">
            WHERE 
              (contents LIKE '%' || #{searchTxt} || '%') 
        </when>
      </choose>
    </if>
  </sql>

HTML

<form class="mt-5" action="/board/list" method="get" id="searchForm">
      <select class="form-select" aria-label="Default select example" name="category">
        <option value="all" selected>전체검색</option>
        <option value="subject">제목</option>
        <option value="contents">내용</option>
        <option value="writer">글쓴이</option>
      </select>
      <input class="form-control" type="text" placeholder="검색어를 입력하세요." aria-label="default input example" name="searchTxt">
      <button class="btn btn-primary" id="btnSearch">SEARCH</button>
    </form>
    <script>
      $("#btnSearch").on("click",function(){
        if($("input[name='searchTxt']").val()==""){
          alert("검색어를 입력해 주세요.");
          return false;
        }
      })
    </script>

ServiceImpl


  public List<ReplyBoardDto> getAllBoardList(
    String category,
    String searchTxt
  ) {
    HashMap<String, Object> hashMap = new HashMap<>();
    hashMap.put("category", category);
    hashMap.put("searchTxt", searchTxt);
    List<ReplyBoardDto> boardList = replyBoardDao.getAllBoardList(hashMap);
    return boardList;
  }

파일 업로드

yml

#server port
server: 
  port: 9091

#spring setting
spring:
  output:
    ansi:
      enabled: always
  datasource:
    driver-class-name: oracle.jdbc.driver.OracleDriver
    url:  jdbc:oracle:thin:@localhost:1521:xe
    username: "-------"
    password: "-------"


  servlet:  
    multipart:  
      max-file-size:  10MB
      max-request-size: 100MB
      location: C:/upload/

file: 
  dir:  "C:/upload/"

logging:
  level:
    root: INFO
    '[com.jjang051.replyboard03]': DEBUG



mybatis:
  mapper-locations: classpath:mapper/sqlmapper/**/*.xml
  config-location: classpath:mapper/config/config.xml
  type-aliases-package: com.jjang051.replyboard03.dto
profile
Working Abroad ...

0개의 댓글