一 JSON编码器的使用
1 编写服务端的控制器
import javax.servlet.http.HttpServletRequest;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyRestController {
@RequestMapping(value = "/person/create", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
public String createPerson(@RequestBody Person p) {
System.out.println(p.getName() + "---" + p.getAge());
return "success, id: " + p.getId();
}
}
2 编写客户端接口
pack