![](https://img-blog.csdnimg.cn/20190918140053667.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
Spring 注解
Spring 注解
幽影相随
这个作者很懒,什么都没留下…
展开
-
@Configuration @ConfigurationProperties
@Configuration@Configuration标注在类上,相当于把该类作为spring的xml配置文件中的,作用为:配置spring容器(应用上下文)@ConfigurationProperties通过 @ConfigurationProperties 注解,我们可以获取大量在 application.properties 或 application.yml 文件中的参数配置。通常可以使用 @Value 注解或着使用 Spring Environment bean 访问这些属性,但是这种注原创 2020-07-29 14:58:09 · 553 阅读 · 0 评论 -
@JsonProperty
@JsonProperty在序列号和反序列化时使用。作用于属性上,作用是把该属性的名称序列化成另一个自己想要的名称。@JsonProperty("name") private String trueName; // 假如 trueName 最后为"小明"// 转化为 json 后: {"name":"小明"} @JsonProperty(access = JsonProperty.Access.READ_ONLY) 只在读时进行(反)序列化。@Target({ElementType.ANNO原创 2020-07-25 19:18:40 · 29742 阅读 · 1 评论 -
@PropertySource @Value 读取配置文件中的值
@PropertySource配置文件路径设置,在类上添加注解,如果在默认路径下可以不添加该注解。@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Repeatable(PropertySources.class) // 允许多个路径例:@PropertySource({“classpath:my/my1.properties”,“classpath:my/my2.properties”})非ap原创 2020-07-25 18:51:04 · 1602 阅读 · 0 评论 -
@Slf4j
@Slf4j@Slf4j 是用作日志输出的,一般会在项目每个类的开头加入该注解,如果想用 log,要么加上private final Logger logger = LoggerFactory.getLogger(当前类名.class);,要么安装插件在代码中可通过 log.info() 打印日志。...原创 2019-11-26 16:41:29 · 114 阅读 · 0 评论 -
拦截器(自定义注解)
均在 config 包下import com.yikao.model.User;import org.springframework.stereotype.Component;import org.springframework.web.method.HandlerMethod;import org.springframework.web.servlet.HandlerIntercepto...原创 2019-07-14 14:49:41 · 1927 阅读 · 0 评论 -
@SessionAttribute
HttpSession 与 @SessionAttribute@SessionAttribute(“emailcode”) String sessionEmailCode@SessionAttribute 在使用时 session 中必须存在对应元素,例如:@SessionAttribute(“emailcode”) String sessionEmailCode,若无"emailcode"...原创 2019-07-14 14:44:32 · 2324 阅读 · 0 评论 -
Spring 自定义注解(验证码)
均在 Validator 包下import org.thymeleaf.util.StringUtils;import javax.servlet.http.HttpServletRequest;import javax.validation.ConstraintValidator;import javax.validation.ConstraintValidatorContext;...原创 2019-07-14 15:07:05 · 1117 阅读 · 0 评论 -
Spring 中的 @Resource 和 @Autowired
总览@Resource 和 @Autowired 都是做bean的注入时使用@Resource 与 @Autowired 作用相当,只不过@Autowired按照byType自动注入。@Resource 并不是Spring的注解,需要导入,但是Spring支持该注解的注入。共同点两者都可以写在字段和setter方法上。两者如果都写在字段上,那么就不需要再写setter方法。不同点@A...原创 2019-06-04 15:24:58 · 2142 阅读 · 0 评论 -
@PathVariable 与 @PathParam
@PathVariable取 url 中的信息@RequestMapping("use/{id}/{name}") public ModelAndView test5(@PathVariable("id") Long ids ,@PathVariable("name") String names){ ModelAndView mv = new ModelAndView(...原创 2019-10-09 17:21:19 · 1549 阅读 · 0 评论