关于spring:SpringMVC常用注解整理

6次阅读

共计 812 个字符,预计需要花费 3 分钟才能阅读完成。

controllerr 层

* @controller: 用于标注管制层服务, 将以后类交给 spring 治理;
* @RestController: 该注解相当 @controller+@RestController 注解
* @ResponseBody:将 controller 的办法的返回对象通过指定的转换器转换为指定的格局后写入到 response 对象的 body 区, 通常用来返回 josn 或字符串等数据 (在应用此注解之后不会再走视图解析器,而是间接将数据写入到输出流中,成果等同于通过 response 对象输入指定格局的数据);
* @RequestMapping: 标注申请门路, 什么申请都能够接管;
* @GetMapping: 标注申请门路, 只接管 get 申请 (查)
* @PostMapping: 标注申请门路, 只接管 post 申请 (增)
* @putMapping: 标注申请门路, 用于批改更新申请
* @DeleteMapping: 标注申请门路, 用于删除申请;
* @PathVariable: 承受申请门路中的占位符的值
* @RequestParam : 将申请参数绑定到被此注解润饰的办法的参数上, 是 springMVC 中接管一般参数的注解;

service 层:

* @Service: 用于标注业务逻辑层, 将以后类交给 spring 治理, 其 getBean 的默认名称是类名(头字母小写),能够 @Service(“xxxx”) 这样来指定

dao 层:

* @Mapper: 将以后 mapper 接口交给 spring 治理, 为接口创立实现类, 并未实现类发明实例, 最初交给 spring 中的 ioc 容器治理 (mapper 接口上也能够不加 @Mapper 注解,通过在启动类上增加 @mapperscan 注解,通过该注解来扫描 com.tedu.dao 包下的所有接口);
* @MapperScan(basePackages = "com.tedu.dao")
* @Repository // 形容数据层实现类, 用于交给 spring 治理
*     
正文完
 0