[英]How to create Modular RESTful web service with Spring Boot and Spring Data Rest
[英]How to create a file comprising of xml data by rest web service in Spring?
大家好,我是春季和休息新手,我想創建一個小模塊,用戶在其中提交一些值,例如說用戶名,姓氏等,然后請求轉到生成文件或.xml的REST服務。將該數據序列化為xml格式的文件。 這類XML Bean序列化。 誰能說出這是如何實現的。 樣例代碼將有很大的幫助。 謝謝
在這里看一下該教程: 使用Spring構建RESTful Web服務 。
從教程:
在rest-servlet.xml
它告訴使用Jaxb2Mashaller進行對象XML映射:
<bean id="jaxbMarshaller"
class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>dw.spring3.rest.bean.Employee</value>
<value>dw.spring3.rest.bean.EmployeeList</value>
</list>
</property>
在getEmployee
它演示了如何接收REQUEST
參數並將其傳遞給getEmployee
方法,然后將其作為串行XML響應傳遞給employee對象。 您可以輕松地修改此getEmployee
方法,以將序列化的員工對象保存到.xml文件中,而不必將其作為響應發送。
@Controller
public class EmployeeController {
@RequestMapping(method=RequestMethod.GET, value="/employee/{id}")
public ModelAndView getEmployee(@PathVariable String id) {
Employee e = employeeDS.get(Long.parseLong(id));
return new ModelAndView(XML_VIEW_NAME, "object", e);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.