Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert springMVC xml to solid object

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to convert springMVC xml and entity objects? for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

RequestMapping comments

@ PostMapping (value = "/ testXmlRequest", produces = "application/xml; charset=UTF-8", consumes = "application/xml; charset=UTF-8") public UserDto testXmlRequest (@ RequestBody UserDto dto) {dto.chgName ("2342424sdfsdfsdf"); return dto;}

Produces sets the data format for the response. Finally, httpMessageConverter selects the corresponding transformation class according to the response media-type of produces.

Consumes sets the data format of the request. Finally, httpMessageConverter selects the corresponding transformation class according to the response media-type of consumes.

Entity class

@ XmlRootElement (name = "xml") public class UserDto {@ XmlElement (name = "id") private Integer id; @ XmlElement (name = "name") private String name; @ XmlElement (name = "sex") private Integer sex; public UserDto () {} public UserDto (Integer id, String name, Integer sex) {this.id = id; this.name = name; this.sex = sex } public void chgName (String name) {this.name = name;}}

The related notes of javax.xml.bind.annotation.*. Will be automatically encapsulated and parsed. Note: the corresponding field cannot have getter and setter, otherwise an error will be reported.

Therefore, for the setting of properties, it is usually OK to create a corresponding builder class.

Examples

Headers:Content-Type=application/xml 12131 test 1 12131 2342424sdfsdfsdf 1 on how to perform springMVC xml and entity object conversion questions are shared here, I hope the above content can be of some help to you, if you still have a lot of doubts to solve, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report