Spring注解
Spring注解
@SpringBootApplication
包含
@Configuration
、@EnableAutoConfiguration
、@ComponentScan
,通常放在主类上。
@Controller
标志是一个控制器类,需要与
@RequestMapping
配合使用。通常做前后端分离的项目用这个注解比较少,因为后端只返回json数据结构,而不是页面。
@RestController
该注解是
@Controller
和@ResponseBody
的组合注解
普通风格 | Rest风格 |
---|---|
@RequestMapping(value=“”,method = RequestMethod.GET) | @GetMapping(value =“”) |
@RequestMapping(value=“”,method = RequestMethod.POST) | @PostMapping(value =“”) |
@RequestMapping(value=“”,method = RequestMethod.PUT) | @PutMapping(value =“”) |
@RequestMapping(value=“”,method = RequestMethod.DELETE) | @DeleteMapping(value =“”) |
@Service
标注该类是一个接口服务
####@Autowired
当我需要从bean工程获取一个
ben
时,spring
就自动为我们装配该标识为@Autowired
的元素
####@Resource
与
Autowired
获取相同的效果,不过该注解并不是spring
提供的,而是j2ee
提供的。两者的差别是Autowired
通过类型匹配,而Resource
通过名称匹配
@Configuration
配置文件注解
@Value
读取
yaml
文件的注解,并可以设置默认值
@Repository
jpa
的dao
注解,通过标注了该注解的类可以操作数据库
@RequestMap
类注解,标明访问该接口的请求地址的开头应该是什么路径
@GetMapping
get
请求的缩写,上表格有说明
@PostMapping
post
请求的缩写,上表格有说明
@PathVariable
路径分隔符变量,用于前端通过地址通配符给后端传递参数
@RequestBody、@RequestParam
参数注解,通过在参数上标注该注解,前端通过
?
后面传递参数
@EnableConfigurationProperties
启用配置文件的注解,读取
yaml
文件的内容到自定义的bean
中
@Component
组件注解
@ConfigurationProperties
与
EnableConfigurationProperties
搭配使用,标注自定义对象中的字段是从yaml
文件中的哪个接口开始匹配
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 +0)の部落阁!
评论