SpringBoot常见注解

1.核心接口

@Controller

@RestController

其中@RestController包括@Controller,另外还默认支持@ResponseBody,对于
返回字符串的方法,我们最好加上@ResponseBody,则就是相当于默认配置

@RestController


2.映射相关

@RequestMapping

这个就像相当于@Mapping(value="xxxx",method=RequestMethod.GET)

@PathVariable

这个我们可以从英文意思看出来是路径的值

@GetMapping(path="html/{message}")
public String index(@PathVariable String message){
}


3.请求相关

@RequestParam

这个就相当于请求的时候带的参数

@GetMapping("/test2")
public String index2(@RequestParam(value="name", required=false, defaultValue="defalult")){
}

参数是name,require=false/true,这个参数是否是必填,不填代表是必填,defaultValue是默认的值


4.响应相关

@ResponseBody
@ResponseEntity

你可能感兴趣的:(Spring,Boot)