Java 在SpringMVC中生成XML响应

Java 在SpringMVC中生成XML响应,java,spring,Java,Spring,我有一个控制器类,我希望它显示用@XmlRootElement注释的模型类的.xml响应。显示所有学员列表的控制器类方法是 @RequestMapping("studentlist") public @ResponseBody StudentList getStudentList() { List<student> studentList = new ArrayList<student>(); studentList.add(new

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

@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);  
 }  

}  

请告诉我缺少什么。我还有一个模型类,它用@XMLElement、@XmlRootElement等进行了适当的注释。由于我是Spring MVC的新手,敬请告知。

首先,您在XML中指定了Spring 3.0。第二,描述正在发生的事情:您是否得到了错误的输出?错误消息?我只是得到简单的响应,而不是xml,输出如下3RobertParerarobert@gmail.com4AndrewStrauss8978767878You请注意,您已经使用JAXB注释对模型类进行了注释。StudentList类也是这样吗?是的,它是一个带注释的模型类@XmlRootElementname=student list公共类StudentList{private list StudentList;protected StudentList{}public StudentList StudentList{this.StudentList=StudentList;}@javax.xml.bind.annotation.xmlementname=student public List getStudentList{return studentList;}
   <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>