首页文章正文

Spring注解,Springboot核心注解

springdoc注解 2023-12-08 21:04 449 墨鱼
springdoc注解

Spring注解,Springboot核心注解

spring4之后加入的注解,原来在@Controller中返回json需要@ResponseBody来配合,如果直接用@RestController替代@Controller就不需要再配置@ResponseBody,默定义一个@Check注解,通过@interface声明一个注解@Target({ ElementType.FIELD}) //只允许用在类的字段上@Retention(RetentionPolicy.RUNTIME) //注解保留在

ˋ^ˊ〉-# @Controller@Controller是@Component注解的一个延伸,Spring会自动扫描并配置被该注解标注的类。此注解用于标注Spring MVC的控制器。下面是使用此注解的示例代码:图片@RestControll@Service:组合注解(组合了@Component注解),应用在Service层(业务逻辑层)。Reponsitory:组合注解(组合了@Component注解),应用在Dao层(数据访问层)。Compone

Spring常用注解@ControllerAdvice//注解定义全局异常处理类@ExceptionHandler //注解声明异常处理方法@SpringBootApplication //@Configuration @EnableAut这里@Autowired注解的意思就是,当Spring发现@Autowired注解时,将自动在代码上下文中找到与其匹配(默认是类型匹配)的Bean,并自动注入到相应的地方去。B @Bean

后台-插件-广告管理-内容页尾部广告(手机)

标签: Springboot核心注解

发表评论

评论列表

51加速器 Copyright @ 2011-2022 All Rights Reserved. 版权所有 备案号:京ICP1234567-2号