SpringBoot常用注解

本文最后更新于:2021年3月19日 晚上

Controller层

注解 含义
@Controller 标明该类为控制器类
@RestController @Controller@ResponseBody的结合,返回字符串,不跳转视图
@RequestMapping URL映射
@GetMapping Get请求,为@RequestMapping(method = RequestMethod.GET)的简写
@PostMapping Post请求,为@RequestMapping(method = RequestMethod.POST)的简写
@PutMapping Put请求,为@RequestMapping(method = RequestMethod.Put)的简写
@DeleteMapping Delete请求,为@RequestMapping(method = RequestMethod.Delete)的简写
@Autowired 自动装配
@PathVariable 路径变量注解

Service层

注解 含义
@Service 标注其为service层的组件

Dao层

注解 含义
@Repository 注解接口,标明其用来执行和数据库相关的操作
@Configuration 用@Configuration注解该类为配置类,等价于XML中配置beans
@Bean @Bean是一个方法级别上的注解,主要用在@Configuration注解的类里,也可以用在@Component注解的类里。添加的bean的id为方法名

主启动类

注解 含义
@MapperScan 通过此注解指定mybatis接口类的路径,即可完成对mybatis接口的扫描。
@SpringBootApplication 标明该类为Spring的引导类,它是一个复合注解,包含了@SpringBootConfiguration,@EnableAutoConfiguration,@ComponentScan这三个注解。

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!