Spring Boot附带了现成的Jackson,它将负责将JSON请求主体解编为Java对象
您可以使用@RequestBody Spring MVC批注将JSON字符串反序列化/解编为Java对象…例如。
例@RestControllerpublic class CustomerController { //@Autowired CustomerService customerService; @RequestMapping(path="/customers", method= RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) public Customer postCustomer(@RequestBody Customer customer){ //return customerService.createCustomer(customer); }}
使用@JsonProperty和相应的json字段名称注释您的实体成员元素。
public class Customer { @JsonProperty("customer_id") private long customerId; @JsonProperty("first_name") private String firstName; @JsonProperty("last_name") private String lastName; @JsonProperty("town") private String town;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)