慕課網《SpringMVC數據綁定入門》筆記java
須要將json串放到http body中發送,用@RequestBody接收,解析爲後臺實體對象時,須要如下依賴。spring
[@Controller](https://my.oschina.net/u/1774615) public String json(User user){ ... } <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.13</version> </dependency>
jackson用於java對象和json對象之間的相互轉換。json
java對象和xml之間的轉換則須要另外一個依賴,包含xml序列化和反序列化的功能。同時須要給實體類加上節點的註解。app
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId> <version>4.3.2.RELEASE</version> </dependency> @XmlRootElement(name="user") class User{ @XmlElement(name="name") private String name; ... }