- 커맨드 객체
- 종류: @ModelAttribute로 설정된 파라미터
- @ModelAttribute어노테이션이 적용된 메서드가 리턴한 객체
- 메서드의 Map, Model, ModelMap 타입의 파라미터를 통해 설정된 모델
@Controller
public class GameSearchController { private SearchService searchService; @ModelAttribute("searchTypeList") public List<SearchType> referenceSearchTypeList() { ArrayList<SearchType> options = new ArrayList<SearchType>(); options.add(new SearchType(1,"all")); options.add(new SearchType(2,"item")); return options; } @RequestMapping("/search/game.do") public ModelAndView search(@ModelAttribute("command")SearchCommand command, ModelMap model) { String[] queryList = new String[]{"one","two"}; model.addAttribute("queryList", queryList); ModelAndView mav = new ModelAndView("search/game"); mav.addObject("searchResult",searchResult); } } |
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html><head> <title></title></head><body> Popular Keyword: <c:forEach var="popularQuery" items="${popularQueryList}"> ${popularQuery} </c:forEach> 검색 list <c:forEach var="searchType" items="${searchTypeList}"> <c:if test="${command.type == searchType.code}">selected</c:if> </c:forEach> <input type="text" name="query" value="${command.query}"/> 검색결과 : ${searchResult} </body></html> |
댓글 없음:
댓글 쓰기