Java开发中常用注解及作用@Controller、@RequestMapping、@ResponseBody、@GetMapping、@PostMapping、@PathVariable

@Controller:
定义控制器,它还允许自动检测定义在类路径下的组件并自动注册

@RequestMapping:
将类似 “/favsoft”这样的URL映射到整个类或特定的处理方法上。@RequestMapping(method=)可以使用 method 属性标记其所接受的方法类型是get(默认)或者post

@ResponseBody:
把返回结果以某种格式返回Json或XML格式

@GetMapping:
get请求路径,查询操作(相当于requestMapping注解设置了get请求)

@PostMapping:
post请求路径,新增操作

@RestController:
返回json数据,而不是路径(相当于@ResponseBody),设置在Controller类上,里面的方法默认加上@ResponseBody注解

@PathVariable:
路径变量,作用在方法的参数前,将URL中的参数映射到方法的参数上,如:/index/1 。1就是参数

@RequestParam:
和注解@PathVariable作用一样,用于获取传入参数的值,如:index?id=1。@RequestParam(value = “id”, required = true)//参数必须要有

@Value:
读取配置文件的属性,作用在类的属性上,读出的数据赋值给属性,有@Value("KaTeX parse error: Expected 'EOF', got '#' at position 14: {}"),@Value("#̲{}"), 如:@Value(…{server.port}"),把yml文件的端口读出来

猜你喜欢

转载自blog.csdn.net/qq_41936224/article/details/106813601