2012-08-27 3 views
0

나는 Spring MVC - Hibernate 애플리케이션을 here으로 개발했다.Spring MVC에서 Spring REST 튜토리얼 오해에 대해서

이제이 코드를 수정하여 here과 같이 REST 응용 프로그램을 만들려고합니다.

클래스 경로에 Jackson 라이브러리를 추가했으며 @XmlRootElement을 추가했습니다. 나는 application/json 요청을 할 경우

@XmlRootElement(name = "persons") 
public class Person implements Serializable { 

하지만 난 여전히 html 코드를 다시 얻을.

내가 뭘 잘못하고 있었는지/잊어 버렸습니까?

내 컨트롤러 :

@RequestMapping(value = "/persons", method = RequestMethod.GET) 
    @ResponseBody 
    public String getPersons(Model model) { 

     logger.info("Received request to show all persons"); 

     // Retrieve all persons by delegating the call to PersonService 
     List<Person> persons = personService.getAll(); 
     model.addAttribute("persons", persons); 

     return "personspage"; 
    } 

는 컨트롤러가 변경되었지만 오류가 발생합니다 :

ype Status report 

message /Buddies/WEB-INF/jsp/main/persons/1.jsp 

description The requested resource (/Buddies/WEB-INF/jsp/main/persons/1.jsp) is not available. 
+0

컨트롤러 방법을 알려주세요. 당신의 메소드에서'Person' 객체를 리턴하고'@ ResponseBody' 주석을 컨트롤러 메소드에도 가지고 있습니까? –

+0

나는 (내가 @PathVariable 추가했지만 오류, 해당 유형 상태 보고서 메시지 /Buddies/WEB-INF/jsp/main/persons/1.jsp 설명을 요청한 리소스를 얻을 수있다 그것을 –

답변

2

컨트롤러는 다음과 같이한다 : Using JAXB to unmarshal/marshal a List<String>을 :

@RequestMapping(value = "/persons/{id}", method = RequestMethod.GET) 
@ResponseBody 
public Person getPerson(@PathVariable int id) { 
    Person person = personService.getPersonById(id); 
    return person; 
} 

당신이 Person 개체의 목록을 반환하려면

, 당신은 참조 추가 래퍼 객체가 필요합니다.

+0

를 추가 한 /들입니다 /WEB-INF/jsp/main/persons/1.jsp)을 사용할 수 없습니다. –

+0

무엇이 문제 일 수 있습니까? –

+0

@Bob :'web.xml'에 어떤 경로가'DispatcherServlet'에 매핑됩니까? –

관련 문제