Giter Club home page Giter Club logo

form's People

Watchers

 avatar

form's Issues

요구사항 추가

타임리프를 사용해서 폼에서 체크박스, 라디오 버튼, 셀렉트 박스편리하게 사용하는 방법을 학습해보자.

기존 상품 서비스에 다음 요구사항이 추가되었다.

image

상품 종류는 ENUM 을 사용한다. 설명을 위해 description 필드를 추가했다.

배송 방식은 DeliveryCode 라는 클래스를 사용한다. code 는 FAST 같은 시스템에서 전달하는 값이고,
displayName 은 빠른 배송 같은 고객에게 보여주는 값이다.

ENUM , 클래스, String 같은 다양한 상황을 준비했다. 각각의 상황에 어떻게 폼의 데이터를 받을 수 있는지
하나씩 알아보자.

라디오 버튼

@Data
public class Item {
    ...
    private ItemType itemType; //상품 종류
public enum ItemType {

    BOOK("도서"), FOOD("음식"), ETC("기타");

    private final String description;

    ItemType(String description) {
        this.description = description;
    }
}

image
image
image

image
타임리프로 생성된 HTML

image
image

image
image

입력 폼 처리

  • th:field의 부가적인 효과

    • 값이 있으면 값까지 출력해줌 (value 속성)
    • 변수이름에 오타가 나면 오류를 내준다
  • 등록 폼보다 수정 폼에서 더 효과를 봄(필드가 많을 경우 매우 유용)

image
image
image

셀렉트 박스

@Data
public class Item {
   ...
    private String deliveryCode;// 배송 방식
/**
 * FAST: 빠른 배송
 * NORMAL: 일반 배송
 * SLOW: 느린 배송
 */
@Data
@AllArgsConstructor
public class DeliveryCode {

    private String code; //시스템에서 전달하는 값
    private String displayName; // 고객에게 보여주는 값
}

image
image

  • 상품 상세와 수정에도 똑같이 적용
  • disabled 를 사용해서 상품 상세에서는 셀렉트 박스가 선택되지 않도록 한다

image

체크박스 - 멀티

image
image
image
image

image

  • <label for="id 값"> 에 지정된 id 가 checkbox 에서 동적으로 생성된 regions1 , regions2 , regions3 에 맞추어 순서대로 입력된 것을 확인할 수 있다.

image

image

image
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.