在Spring MVC中生成XML响应

时间:2014-11-23 00:19:39

标签: java spring

我有一个控制器类,我希望它显示模型类的.xml响应,该响应用@XmlRootElement注释。显示所有学生列表的Controller类方法是

@RequestMapping("studentlist")  
   public @ResponseBody  
   StudentList getStudentList() {  
   List<student> studentList = new ArrayList<student>();  
   studentList.add(new Student(3, "Robert", "Parera", "robert@gmail.com", "88"));  
   studentList.add(new Student(93, "Andrew", "Strauss","andrew@gmail.com", "89"));  
   studentList.add(new Student(239, "Eddy", "Knight", "knight@gmail.com",  "79"));  
   return new StudentList(studentList);  
 }  

}  

我添加了@ResponseBody,但该类仍未显示.xml响应这是我的web.xml

   <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans     
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <context:component-scan base-package="com.javasample.common.controller" />

    <mvc:annotation-driven />

  </beans>

请告知遗漏的内容。我也有模型类,它使用@XMLElement@XmlRootElement等进行了正确的注释。请注意,我是 Spring MVC 的新手。

0 个答案:

没有答案