복붙노트

[SPRING] 스프링의 경로 속성 [닫힘]

SPRING

스프링의 경로 속성 [닫힘]

누구든지 경로 속성이 html 폼의 객체를 Spring의 Java 클래스로 바인딩하는 방법을 설명 할 수 있습니까? 나는 웹 프레임 워크를 봄으로 초보자 다.

해결법

  1. ==============================

    1.길고 짧게 경로 속성은 자바 빈 규칙을 사용하여 자바 속성에 바인딩됩니다. 예를 들면 다음과 같은 양식 :

    길고 짧게 경로 속성은 자바 빈 규칙을 사용하여 자바 속성에 바인딩됩니다. 예를 들면 다음과 같은 양식 :

    <form:form method="post" modelAttribute="theStudent">
      Name: <form:input type="text" path="name"/>
      Cool?: <form:input type"checkbox" path="cool"/>
      <button>Save</button>
    </form:form>
    

    그리고 컨트롤러 핸들러 방식 :

    @RequestMapping(...)
    public String updateStudent(@ModelAttribute("theStudent") Student student) {
      // ...
    }
    

    Student 클래스가 다음 속성을 사용하여 정의 된 경우 자동으로 바인딩됩니다.

    public class Student {
      private String name;
      public String getName() { return this.name; }
      public void setName(String name) { this.name = name; }
    
      private boolean cool;
      public boolean isCool() { return this.cool; }
      public void setCool(boolean cool) { this.cool = cool; }
    }
    

    JavaBeans 규칙에 대한 자세한 내용은 사양 문서의 8.3 절에서 확인할 수 있습니다.

  2. from https://stackoverflow.com/questions/17647050/path-attribute-in-spring by cc-by-sa and MIT license