Summary different functional annotation springboot

1 and an example of the returned string annotations

@ResponseBody
@RequestMapping("/in")
String hello() {
return "hello";
}

2 returns json object annotations and examples

@RequestMapping(value = "/{id}",method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<User> getUserById (@PathVariable("id") String id){
//初始化用户信息
initUserInfo();
User result = users.get(id);
HttpStatus status = result != null ? HttpStatus.OK : HttpStatus.NOT_FOUND;
if(result == null){
throw new UserNotFountException(id);
}
return new ResponseEntity<User>(result,status);
}

Example 3 mvc annotations and return the html page

 

Guess you like

Origin www.cnblogs.com/hustdc/p/11333068.html
Recommended