以贴上代码的形式:
@Controller
@Controller
public class HelloController {
@RequestMapping("/boot/hello")
public @ResponseBody String hello(){
return "你终于进来了";
}
}
@RestController @GetMapping @PostMapping
@RestController //这个注解 相当于 @Controller + @ResponseBody 只可以返回一个字符串或者对象 如果要返回一个网页就不可以了
public class MVCController {
@Autowired
private User user;
@RequestMapping("/boot/getUser")
public Object getUser() {
return user;
}
/**
* @Description: @GetMapping 只支持Get请求 @RequestMapping + RequestMethod.Get
* : @GetMapping 等价于 @RequestMapping(value = "/boot/getUser",method = RequestMethod.GET)
* @return: java.lang.Object
* @Author: Tudengdaji
* @date: 2019/10/11
*/
@GetMapping("/boot/getUser1")
public Object getUser1() {
return user;
}
/**
* @Description: @PostMapping 只支持Get请求 @RequestMapping + RequestMethod.Post
* : @PostMapping 等价于 @RequestMapping(value = "/boot/getUser",method = RequestMethod.POST)
* @return: java.lang.Object
* @Author: Tudengdaji
* @date: 2019/10/11
*/
@PostMapping("/boot/getUser2")
public Object getUser2() {
return user;
}
}