コード例 #1
0
 @RequestMapping(
     value = "/{id}",
     method = RequestMethod.DELETE,
     headers = "Accept=application/json")
 public ResponseEntity<String> deleteFromJson(@PathVariable("id") Long id) {
   Userinfo userinfo = userService.findUserinfo(id);
   HttpHeaders headers = new HttpHeaders();
   headers.add(CONTENT_TYPE, APPLICATION_JSON);
   if (userinfo == null) {
     return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
   }
   userService.deleteUserinfo(userinfo);
   return new ResponseEntity<String>(headers, HttpStatus.OK);
 }
コード例 #2
0
 @RequestMapping(headers = "Accept=application/json")
 @ResponseBody
 public ResponseEntity<String> listJson() {
   HttpHeaders headers = new HttpHeaders();
   headers.add(CONTENT_TYPE, "application/json; charset=utf-8");
   List<Userinfo> result = userService.findAllUserinfoes();
   return new ResponseEntity<String>(Userinfo.toJsonArray(result), headers, HttpStatus.OK);
 }
コード例 #3
0
 @RequestMapping(method = RequestMethod.POST, headers = "Accept=application/json")
 public ResponseEntity<String> createFromJson(@RequestBody String json) {
   Userinfo userinfo = Userinfo.fromJsonToUserinfo(json);
   userService.saveUserinfo(userinfo);
   HttpHeaders headers = new HttpHeaders();
   headers.add(CONTENT_TYPE, APPLICATION_JSON);
   return new ResponseEntity<String>(headers, HttpStatus.CREATED);
 }
コード例 #4
0
 @RequestMapping(value = "/{id}", method = RequestMethod.PUT, headers = "Accept=application/json")
 public ResponseEntity<String> updateFromJson(
     @RequestBody String json, @PathVariable("id") Long id) {
   HttpHeaders headers = new HttpHeaders();
   headers.add(CONTENT_TYPE, APPLICATION_JSON);
   Userinfo userinfo = Userinfo.fromJsonToUserinfo(json);
   if (userService.updateUserinfo(userinfo) == null) {
     return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
   }
   return new ResponseEntity<String>(headers, HttpStatus.OK);
 }
コード例 #5
0
 @RequestMapping(value = "/{id}", method = RequestMethod.GET, headers = "Accept=application/json")
 @ResponseBody
 public ResponseEntity<String> showJson(@PathVariable("id") Long id) {
   Userinfo userinfo = userService.findUserinfo(id);
   HttpHeaders headers = new HttpHeaders();
   headers.add(CONTENT_TYPE, "application/json; charset=utf-8");
   if (userinfo == null) {
     return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
   }
   return new ResponseEntity<String>(userinfo.toJson(), headers, HttpStatus.OK);
 }