\ [Spring]FormTag & DataBinding - (1)TextField :: Something New
728x90
반응형


개발 과정
1.student 클래스 생성

2.StudentController클래스 추가

3. Html 만들기

4.프로세스 form을 생성

5.html- confirmation page생성

 

1.student 클래스 생성


new-class-Student default

public class Student{
 private String firstName;
 private String LastName;
 
 public Student(){
 }

get,set 추가




2.StudentController클래스 추가


new-class-StudentController

@Controller
@RequestMapping("/student")
public class StudentController{
@RequestMapping("/showForm")
public Strinng showForm(Model theModel){
         
       Student theStudent = new Student();
       theModel.addAttriute("stuedent",theStudent);  
       return "student-form";
}


//4.프로세스 form을 생성

@RequestMapping("/processForm")
 public String processForm(@ModelAttribut("student" Student theStudent){
    //log the input data
   system.out.pringln("theStudent :"+tehStudent.getFirstName()
    + " " + theStuden.getLastName());   

	return "student-confirmation";
}
}

 

3. Html 만들기



WEN-WEB-INF-VIEW-STUDEN-FORM.JSP


<body>
//form을 로드할 때 스프링은 student.getFirstName(),getLastName을 호출함
<form:form action="processForm" modelAttribute="student">
First name: <form:input path="firsthName" />
<br><br>
First name: <form:input path="firsthName" />
//submit할 때는 set~~을 호출함
<input type="submint" value="Submit" />

 



5.html- confirmation page 만들기

<body>

 The student is confirmed : ${studen.first}${student.lastName}


main-menu.jsp  <a href= "student/showform">Student form </a>



728x90

'JAVA Spring FRAMEWORK' 카테고리의 다른 글

[JAVA]JDBC란?  (0) 2024.11.13
[SQL]Inner Join vs Outer Join  (1) 2024.08.31
디자인 패턴이란?  (0) 2024.06.24
[Spring Boot ] Spring Initializr 로 시작하기  (0) 2023.03.14
[Spring MVC]Developing Spring Controllers and Views  (0) 2021.11.17

+ Recent posts