728x90
📍 하고 싶은 것 ?
<c:forEach var="cnt" begin="0" end="5" step="1">
<input type="text" name="userName" readonly placeholder="userName_${cnt}"/>
<br/>
</c:forEach>
- jsp에 form이 있고, 이 form 안에 반복되는 name이 같은 input이 있음.
- 컨트롤러에서 찍어봤을 때는
- 라이언,어피치,마리오,루이지,피치공주,( )
- 이런 식으로 찍힘.
- 아마 같은 이름의 requestParam 으로 받아가지고 그래서 뒤에 , 로 이어서 붙어지는 것 같음.
- 값이 없어도 찍히기는 함!!
- 생각해봤을 때는.... request.getParameterValues("userId")[0]; 과 같이 받아서 계속 돌려야하나..?
- 근데 이거는 너무... ㅠㅠㅠ... 그래서 찾아봄!!!!
📍 ➡️➡️ 찾아본 방법을 적용해보자 !!
- VO
public class UserVO {
private String userName;
private List<UserVO> userVOList;
~ getter 생략 ~
~ setter 생략 ~
}
- Controller
@Controller
public class UserController{
@RequestMapping("~생략~")
public String tbUser( @Modelattribute UserVO userVO ){
List<UserVO> userVOList = userVO.getUserVOList();
for( UserVO lst : userVOList ){
System.out.println( lst.getUserName() );
}
}
}
/* 결과 ::
** 라이언
** 어피치
** 루이지
** 피치공주
**
*/
/*
끝에 userName_5는 없는데도
form을 통해서 전달되기 때문에,
빈 값이 찍히는 것임.
아마 사용할 때는
lst.getUserName() != ""
과 같이 조건을 사용해서 써야할 것 같음.
*/
- jsp
<!-- jsp 단 -->
<c:forEach var="cnt" begin="0" end="5" step="1">
<input type="text" id="userName" name="userVOList[${cnt}].userName" readonly placeholder="userName_${cnt}"/>
</c:forEach>
출처 :
https://blog.naver.com/mk1126sj/220958680523
https://brightmango.tistory.com/374
https://tjdguqdl.tistory.com/54?category=908348
개발 공부를 위한 블로그 입니다.
오류가 있다면 댓글로 알려주세요!
감사합니다.

728x90
'스프링' 카테고리의 다른 글
[Spring] Only a type can be imported. com.oreilly.servlet.MultipartRequest resolves to a package (0) | 2023.07.06 |
---|---|
[iBatis/MyBatis] 아이/마이바티스 in절 사용 (0) | 2023.05.04 |
[Spring] @RequestBody (0) | 2023.04.17 |
[iBatis] parameterClass = "Map" (∵ 파라미터가 여러 개 일 때!) (0) | 2023.04.04 |
[iBatis, MyBatis] 비교 정리(Dynamic Query) (0) | 2023.04.04 |