반응형

JSP Form에서 VO가 여러개로, 즉 list로  넘기고 controller에서 받아야 하는 경우

List를 사용하면 됨

 

1. VO객체

BoardVo 클래스 안에 List<BoardVO>를 선언하고 getter와 setter도 만들었음!

public class BoardVo {
	
	private String 	boardType;
	private int 	boardNum;
	private String 	boardTitle;
	private String 	boardComment;
	private String 	creator;
	private String	modifier;
	private int totalCnt;

	
	private List<BoardVo> boardVoList;
	

	
	public List<BoardVo> getBoardVoList() {
		return boardVoList;
	}
	public void setBoardVoList(List<BoardVo> boardVoList) {
		this.boardVoList = boardVoList;
	}
	
	

 

2. JSP의 Form 

name은  List객체이름[index].property 이름 

<form:form commandName="boardVo" class="boardWrite" action="/board/boardWriteAction.do">
		<select name="boardVoList[0].boardType" >
				<c:forEach items="${codeList}" var="list">
				<option value="${list.codeId}">${list.codeName}</option>
				</c:forEach>
		</select>
 <input name="boardVoList[0].boardTitle" type="text" size="50" value="${board.boardTitle}"  maxlength="24">

 

반응형

 

 

3. Controller

파라미터를 전달받을땐 List가 아닌 Vo로 받음

//글등록 수행
	@RequestMapping(value = "/board/boardWriteAction.do", method = RequestMethod.POST)
	@ResponseBody
	public String boardWriteAction(Locale locale, BoardVo boardVo) throws Exception{
	
		
		HashMap<String, String> result = new HashMap<String, String>();
		CommonUtil commonUtil = new CommonUtil();
		int resultCnt = 0;
		
		System.out.println(boardVo.getBoardVoList().get(0).getBoardType());
		System.out.println(boardVo.getBoardVoList().get(0).getBoardTitle());
		System.out.println(boardVo.getBoardVoList().get(0).getCreator());
		
		
		resultCnt=boardService.boardInsert(boardVo);

List에 담긴 값(프로퍼티) 호출 시에는

Vo이름.get리스트이름().get(index).get프로퍼티()

 

4. Service Impl

List를 호출할 때는 vo이름.getlist이름().get(인덱스) 해서 사용하면 됨!

@Override
	public int boardInsert(BoardVo boardVo) throws Exception {
		
		int[] results= new int[boardVo.getBoardVoList().size()];
		int result=1;
		
		for(int i=0; i<boardVo.getBoardVoList().size();i++) {
			results[i]=boardDao.boardInsert(boardVo.getBoardVoList().get(i));

			result *= results[i];
		}
		
		return result;
	}
반응형
반응형

VO에 변수를 String배열변수 따로, 일반 String 변수 따로 생성함.

데이터 교환은 배열로 하고 DB저장할땐 String으로 하려 함.

 

input 은 배열에다 받음

 

 

Controller에서 VO로 받고

 

반복문으로 각 인덱스의 값을 String 변수에 넣어주고 insert를 반복함

반응형

+ Recent posts