TigerDemon

섹션 9 Mybatis DynamicSql 적용 본문

2024-SWLUG/웹페이지 만들기

섹션 9 Mybatis DynamicSql 적용

호랑2D 2024. 11. 15. 01:25

스프링 부트 웹 개발 입문 - 따라하며 배우기

https://inf.run/bhSZP

 

스프링 부트 웹 개발 입문 - 따라하며 배우기 강의 | IT늦공 김부장 - 인프런

IT늦공 김부장 | 따라하며 만들다 보면 어느새 알게 되는, 스프링 부트를 이용한 자바 웹 개발!, 처음 시작하는 스프링부트, 누구나 쉽게! 스프링 부트, 초보자도 쉽게 시작할 순 없을까요? 스프

www.inflearn.com

 

조회 처리

controller

@PostMapping("/menu_search")
public String doSearch( @RequestParam("start_date") String strStartDate,
                        @RequestParam("end_date") String strEndDate,
                        @RequestParam(value = "coffee", defaultValue = "ALL") String strCoffee,
                        @RequestParam("kind") String strKind,
                        Model model

){

    log.info("strStartDate :"+strStartDate);

    List<Map<String, Object>> list = menuSvc.doSerch(strStartDate,strEndDate, strCoffee,strKind );

    model.addAttribute("list", list);

    return "/v1/menu/menu";
}

 

service

public List<Map<String, Object>> doSerch(String strStartDate, String strEndDate, String strCoffee, String strKind) {
    List<Map<String, Object>> list = menuDao.doSerch(strStartDate,strEndDate, strCoffee,strKind );
    return list;
}

 

 

다중 데이타 처리 방법

체크박스

<td><input type="checkbox" name="chkCoffeeNo" th:value="${prod.get('no')}"></td>

 

controller

/* 가격 수정 - 다중 체크 */
    @PostMapping("/menu_updatePrice")
    public String doUpdatePrice(@RequestParam("chkCoffeeNo") List<String> chkList,
                                @RequestParam("hidden_price") String strPrice
    ){

        if(chkList != null){
            for(String strNo : chkList){
                 int int1 = menuSvc.doInsertLog(strNo, strPrice);
                 int int2 = menuSvc.doUpdatePrice(strNo, strPrice);
            }
         

        return "redirect:/v1/menu";

    }

 

service

/* 가격변경 */
public int doUpdatePrice(String strNo, String strPrice) {
    int int2 = menuDao.doUpdatePrice(strNo, strPrice);
    return int2;
}

/* 가격 로그입력 */
public int doInsertLog(String strNo, String strPrice) {
    int int1 = menuDao.doInsertLog(strNo, strPrice);
    return int1;
}

 

 

다중 데이타 처리를 좀 더 스마트하게

가격 수정부분 변경 - menu controller

    /* 가격 수정 - 다중 체크 */
    @PostMapping("/menu_updatePrice")
    public String doUpdatePrice(@RequestParam("chkCoffeeNo") List<String> chkList,
                                @RequestParam("hidden_price") String strPrice
    ){

        if(chkList != null){
//            for(String strNo : chkList){
//                 int int1 = menuSvc.doInsertLog(strNo, strPrice);
//                 int int2 = menuSvc.doUpdatePrice(strNo, strPrice);
//            }
              int int1 = menuSvc.doInsertLogOne(chkList, strPrice);
              int int2 = menuSvc.doUpdatePriceOne(chkList, strPrice);
        }

        return "redirect:/v1/menu";

    }

 

 

 

'2024-SWLUG > 웹페이지 만들기' 카테고리의 다른 글

섹션 11 - 배포하기  (0) 2024.11.15
섹션 10 VO사용하기  (0) 2024.11.15
세션 8 DB 연결  (0) 2024.11.13
세션 7 환경설정 변경  (0) 2024.11.13
세션 6 Front와 Back-end가 만나다.  (0) 2024.11.13