SpringBoot项目中常见的注解

 

@Controller:修饰class,用来创建处理http请求的对象
@RestController:Spring4之后加入的注解,原来在@Controller中返回json需要@ResponseBody来配合,如果直接用@RestController替代@Controller就不需要再配置@ResponseBody,默认返回json格式。
@RequestMapping:配置url映射

返回json的方式:

@ResponseBody
@RequestMapping("/hello")
public String hello() {
    return "Hello World";
}

 返回页面的方式:

@RequestMapping("/")
    public String index(ModelMap map) {
        map.addAttribute("host", "我是yaohuiqin");
        return "index";
    }

  

posted @ 2018-07-24 17:36  yaohuiqin  阅读(132)  评论(0编辑  收藏  举报