Spring

Spring 일지 #28 (20210914) 화면 구현(물품 목록)

uni5948 2021. 9. 27. 16:42

28. 물품 목록

-물품 목록

 *select_item get 생성(SellerController.java)

... ...

// 127.0.0.1:8080/ROOT/seller/select_item

    @GetMapping(value = "/select_item"// 물품목록

    public String selectItemGet(Model model) {

        List<Itemlist = iRepository.findAllByOrderByNoAsc();

        model.addAttribute("list"list);

        return "select_item";

    }

... ...

 

 *목록 페이지 구성(select_item.jsp)

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>select_item.jsp</title>

</head>

<body>

    <a th:href="@{/seller/insert_item}">물품등록</a>

    <hr />

    <table border="1">

        <tr>

            <th>번호</th>

            <th>물품코드</th>

            <th>물품명</th>

            <th>물품내용</th>

            <th>가격</th>

            <th>수량</th>

            <th>등록일자</th>

            <th>이미지 등록</th>

        </tr>

        <tr th:each="itm, idx : ${list}">

            <td th:text="${idx.count}"></td>

            <td th:text="${itm.no}"></td>

            <td th:text="${itm.name}"></td>

            <td th:text="${itm.content}"></td>

            <td th:text="${itm.price}"></td>

            <td th:text="${itm.quantity}"></td>

            <td th:text="${itm.regdate}"></td>

            <td> <a th:href="@{/seller/insert_item_image(no=${itm.no})}">이미지 등록</a></td>

        </tr>

    </table>

</body>

</html>

 

 *목록 확인

목록 확인

 

-필요없는 내용 빼기(content 빼기)

 *entity 생성(ItemProjection.java)

 *표시할 get 변수만 입력한다.

 

package com.example.entity;

 

import java.util.Date;

 

public interface ItemProjection {

 

    // 참고 : Item.java엔티티를 참고함

    // 필요한 get 변수만 설정

    Long getNo();

    String getName();

    Long getPrice();

    Long getQuantity();

    Date getRegdate();

}

 

 *저장소 조건 추가(ItemRepository.java)

... ...

List<ItemProjectionfindAllByOrderByNoAsc();

 

 *select_item수정(SellerController.java)

 

... ...

 List<ItemProjectionlist = iRepository.findAllByOrderByNoAsc();

... ...

 

 *jsp 수정

 *content 제거

 

... ...

<table border="1">

        <tr>

            <th>번호</th>

            <th>물품코드</th>

            <th>물품명</th>

            <th>가격</th>

            <th>수량</th>

            <th>등록일자</th>

            <th>이미지 등록</th>

        </tr>

        <tr th:each="itm, idx : ${list}">

            <td th:text="${idx.count}"></td>

            <td th:text="${itm.no}"></td>

            <td th:text="${itm.name}"></td>

            <td th:text="${itm.price}"></td>

            <td th:text="${itm.quantity}"></td>

            <td th:text="${itm.regdate}"></td>

            <td> <a th:href="@{/seller/insert_item_image(no=${itm.no})}">이미지 등록</a></td>

        </tr>

    </table>

... ...

 

 *화면 확인

목록 확인