본문 바로가기
발전소/동아리 및 스터디

[코딩 스터디 2기] : 12주차

by 오주현 2022. 5. 21.
반응형

오늘 스터디도 정상적으로 진행했다. 한 쌤이 바쁘셔서 못 나오셔서 3명에서 진행을 했는데 리뷰, 발표 모두 잘 마무리 했다.

 

발표
@GetMapping("/touchCheck")
public String touchCheck(Model model) throws Exception {

    List<CarDTO> carDTOList = iCarListService.getFullCarList();

    model.addAttribute(carDTOList);
    model.addAttribute("checkDTO", new CheckDTO());

    return "carCheck/touchCheck";
}

컨트롤러에서 Model 객체에 담아 차량 정보가 담긴 carDTOList와 같이 View로 넘겨준다.

<form th:action="@{/carCheck/touchCheckSave}" th:object="${checkDTO}" method="post">
    <table class="table table-striped">
        <thead>
        <tr>
            <th scope="col">이름</th>
            <th scope="col">연락처</th>
            <th scope="col">차량번호</th>
            <th scope="col">주소</th>
            <th scope="col">구분</th>
            <th scope="col">주차완료</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="m: ${carDTOList}">
            <td th:text="${m.name}"></td>
            <td th:text="${m.phoneNumber}"></td>
            <td th:text="${m.carNumber}"></td>
            <td th:text="${m.address}"></td>
            <td th:text="${m.sort}"></td>
            <td>
                <input th:type="checkbox" th:field="*{checkList}" th:value="true">
            </td>
        </tr>
        </tbody>
    </table>
    <button th:type="submit" th:text="저장하기"></button>
</form>

th:object에서 Model 객체에 담겨온 checkDTO로 값을 받도록 넣어주고, 차량 리스트만큼 체크 박스가 생성되게 한다. checkDTO에 있는 checkList 필드를 지정해주고 값이 있을 때 true를 넘기도록 한다.


문제점 :

값이 체크되지 않은 경우, false인 경우에 null도 아니고, false도 아닌 아무런 값이 들어가지 않는다. 다른 방법으로 체크 박스를 두 개 만들어서 하나는 true 값이, 하나는 false 값이 들어가도록 만들어 보기도 했는데 만약 체크 하기를 깜빡한 줄이 있다면 그것도 문제여서 패스했다.

디폴트 값을 false로 지정하고 체크한 경우엔 true, 체크하지 않은 경우엔 false로 받는 게 베스트인데 잘 안 되는 중이다.

또, chekcDTO에 List값 말고 check 값 1개가 무조건 들어가는데 DTO에서 List와 일반 값을 분리하는 것도 고민중이다.

 

 

리뷰
@Data
public class CheckListVo {
    private List<CarDTO> carDtoList;
}
// 터치 체크 로직 페이지
    @GetMapping("/touchCheck")
    public String touchCheck(Model model) throws Exception {

        List<CarDTO> carDTOList = iCarListService.getFullCarList();

        CheckListVo checkListVo = new CheckListVo();
        checkListVo.setCarDtoList(carDTOList);

        model.addAttribute("carDTOList", carDTOList);
        model.addAttribute("checkListVo", checkListVo);

        return "carCheck/touchCheck";
    }

    // 터치 체크 저장 로직
    @PostMapping("/touchCheckSave")
     public String touchCheckSave(@ModelAttribute CheckListVo checkListVo) throws Exception {
<tr th:each="m: ${checkListVo.carDtoList}">

    <td>
        <input type="text" class="btn btn-outline-primary" th:field="*{carDtoList[__${mStat.index}__].name}" readonly>
    </td>

 

 

오늘 한 쌤에게 많은 도움을 받아 내가 어려워 하던 부분을 좋게 수정할 수 있었다. 아직 Service와 Mapper 부분을 수정하지 못 해서 제대로 로직 정리를 하지는 않았지만 조만간 완성 시키고 다시 로직 정리를 해 볼 예정이다.

반응형

댓글