일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- unboxing
- 콜렉션
- wrapper
- 제네릭
- start.spring.io
- boxing
- Java
- 싱글턴
- 빌드
- 언박싱
- https://start.spring.io
- suvlet
- Scanner
- 클래스
- 제너릭
- 자동형변환
- Jenkins
- Short
- 내장객체
- bootstrap
- 무한
- 컬렉션
- 싱글톤
- 루프
- 인텔리제이
- dependency
- 스프링
- 메소드
- maven
- 박싱
Archives
- Today
- Total
Developer Gonie
스프링(Spring), <input type="text" name=???> 배열 형태로 보내기 본문
K-DigitalTraining 강의/11. Spring
스프링(Spring), <input type="text" name=???> 배열 형태로 보내기
이대곤 2022. 9. 13. 19:04* 이번 게시물은 <input type="text" name=???> 에서 name 부분을 배열 형태로 작성할 수 있는지 처음 알게되어 작성하였다.
컨트롤러로 전송하고 싶은 부분
* examlist 라는 이름은 ExamListBean 클래스의 멤버변수 이름임에 주의하자.

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="test.prd" method="post">
<input type="text" name="examlist[0].title" value="1번"><br>
<input type="text" name="examlist[0].subject" value="국어"><br>
<input type="text" name="examlist[0].limit_time" value="30"><br><br>
<input type="text" name="examlist[1].title" value="2번"><br>
<input type="text" name="examlist[1].subject" value="영어"><br>
<input type="text" name="examlist[1].limit_time" value="60"><br><br>
<input type="text" name="examlist[2].title" value="3번"><br>
<input type="text" name="examlist[2].subject" value="수학"><br>
<input type="text" name="examlist[2].limit_time" value="100"><br><br>
<input type="submit" value="전송">
</form>
</body>
</html>
위와같이 처리하기 위해 필요한 2개의 Bean 클래스
import java.util.List;
public class ExamListBean {
private List<ExamBean> examlist;
public ExamListBean() {
super();
}
public ExamListBean(List<ExamBean> examlist) {
super();
this.examlist = examlist;
}
public List<ExamBean> getExamlist() {
return examlist;
}
public void setExamlist(List<ExamBean> examlist) {
this.examlist = examlist;
}
}
public class ExamBean{
private String title;
private String subject;
private String limit_time;
public ExamBean() {
super();
}
public ExamBean(String title, String subject, String limit_time) {
super();
this.title = title;
this.subject = subject;
this.limit_time = limit_time;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getLimit_time() {
return limit_time;
}
public void setLimit_time(String limit_time) {
this.limit_time = limit_time;
}
}
컨트롤러에서 받은 값 출력해보기
@Controller
public class TestController {
private final String command = "test.prd";
private String getPage ="test";
@RequestMapping(value = command, method = RequestMethod.GET)
public String showInsertForm() {
System.out.println("TestController에 GET 요청 들어옴");
return getPage;
}
@RequestMapping(value = command, method = RequestMethod.POST)
public String doAction(ExamListBean ebList) throws UnsupportedEncodingException {
System.out.println("TestController에 POST 요청 들어옴");
ArrayList<ExamBean> list = (ArrayList<ExamBean>) ebList.getExamlist();
System.out.println(list.get(0).getSubject());
System.out.println(list.get(0).getLimit_time());
System.out.println(list.get(0).getTitle());
System.out.println();
System.out.println(list.get(1).getSubject());
System.out.println(list.get(1).getLimit_time());
System.out.println(list.get(1).getTitle());
return getPage;
}
}
/*
국어
30
1번
영어
60
2번
*/
'K-DigitalTraining 강의 > 11. Spring' 카테고리의 다른 글
지금까지 배웠던 어노테이션 (0) | 2022.09.05 |
---|---|
유효성 검사 어노테이션 (0) | 2022.09.05 |
form에서 입력한 값을 컨트롤러의 요청처리 메소드 쪽에서 받는 2가지 방법 (0) | 2022.09.01 |
로그인 화면으로 이동했다가 다시 원래 위치로 돌아가도록 구현하는 방법 (0) | 2022.09.01 |
스프링(Spring)에서 jsp 파일을 바로 실행하기 위한 jsp 파일 위치 (0) | 2022.08.28 |
Comments