Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- OGNL
- 안드로이드
- layout
- 생성자
- struts2
- 기본
- mybatis
- Eclips
- 어노테이션
- Android
- AWT
- HTML
- 예외처리
- 오버로딩
- JSP
- 전화걸기
- oracle
- 이클립스
- 국제화
- Spring
- 메소드
- 배열
- 에러페이지
- paint
- 메서드
- Menu
- Graphic
- JavaScript
- Java
- 클래스
Archives
- Today
- Total
note
뷰에 모델 데이터 전달하기 본문
@ModelAttrubyte()
메소드 위에 명시만으로 JSP 에서 호출가능
dispatcher-servlet.xml
madvirus.spring.chap06.service/SearchCommand.java
package madvirus.spring.chap06.service;
public class SearchCommand {
private String type;
private String query;
private int page;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
}
madvirus.spring.chap06.service/SearchResult.java
package madvirus.spring.chap06.service;
public class SearchResult {
}
madvirus.spring.chap06.service/SearchService.java
package madvirus.spring.chap06.service;
public class SearchService {
public SearchResult search(SearchCommand command){
return new SearchResult();
}
}
madvirus.spring.chap06.service/SearchType.java
package madvirus.spring.chap06.service;
public class SearchType {
private int code;
private String text;
public SearchType(int code, String text) {
super();
this.code = code;
this.text = text;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
madvirus.spring.chap06.controller/GameSearchController.java
package madvirus.spring.chap06.controller;
import java.util.ArrayList;
import java.util.List;
import madvirus.spring.chap06.service.SearchCommand;
import madvirus.spring.chap06.service.SearchResult;
import madvirus.spring.chap06.service.SearchService;
import madvirus.spring.chap06.service.SearchType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class GameSearchController {
@Autowired
private SearchService searchService;
@ModelAttribute("searchTypeList")
public List referenceSearchTypeList(){
List options = new ArrayList();
options.add(new SearchType(1, "전체"));
options.add(new SearchType(2, "아이템"));
options.add(new SearchType(3, "캐릭터"));
return options;
}
@ModelAttribute("popularQueryList")
public String[] getpopularQueryList(){
return new String[] {"게임","창천2","위메이드"};
}
@RequestMapping("/search/main.do")
public String main() {
return "search/main";
}
@RequestMapping("/search/game.do")
public ModelAndView search(@ModelAttribute("command") SearchCommand command){
ModelAndView mav = new ModelAndView("search/game");
System.out.println("검색어 = "+command.getQuery().toUpperCase());
SearchResult result = searchService.search(command);
mav.addObject("searchResult",result);
return mav;
}
@ExceptionHandler(NullPointerException.class)
public String handleNullPointException(NullPointerException ex){
return "error/nullException";
}
public void setSearchService(SearchService searchService){
this.searchService = searchService;
}
}
search/main.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
게임 검새ㅐㄱ 메인
인기 키워드 : ${popularQuery}
String 배열로 부터 index에 접근하여 데이터 빼기
search/game.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
게임 검색 결과
인기 키워드 :
${popularQuery}
검색 결과 :${search.Result}
'JSP > Spring' 카테고리의 다른 글
Spring 요청 URI 매칭 (0) | 2012.03.05 |
---|---|
Spring 유효성 체크 (0) | 2012.03.05 |
Spring 컨트롤러 메서드의 리턴 타입 (0) | 2012.03.05 |
@RequestHeader 어노테이션을 이용한 헤더 매핑 (0) | 2012.03.05 |
@CookieValue 어노테이션을 이용한 쿠키 매핑 (0) | 2012.03.05 |