spring中相关注解

@Configuration:标注在类上,相当于把该类作为spring的xml配置文件中的,作用为:配置spring容器(应用上下文)

@ComponentScan:告诉Spring 哪个packages 的用注解标识的类 会被spring自动扫描并且装入bean容器。

具体使用: @ComponentScan(basePackages={"cn.ydhl.front.auth.controller"})

@EnableWebMvc:注解用来开启Web MVC的配置支持。

@Bean:产生一个bean的方法,并且交给Spring容器管理,并告诉spring容器,你可以从这个方法中拿到一个bean。

具体使用:

@Bean

publicMessageSourcemessageSource() {

       StaticMessageSourcemessageSource=newStaticMessageSource();

        messageSource.setUseCodeAsDefaultMessage(true);

        return  messageSource;

}

@ImportResource:主要用于IavaConfig中,作用为注入相关xml配置

具体使用:@ImportResource({"classpath:/ydhl-front-auth-dubbo.xml"})

@Value:获取properties配置文件中的配置值,大大简化了读取配置文件的代码

spring中相关注解_第1张图片

@SuppressWarnings:告诉编译器忽略指定的警告,不用在编译完成后出现警告信息。

使用示例:

@SuppressWarnings("")

@SuppressWarnings({})

@SuppressWarnings(value={})

@DateTimeFormat:时间格式转换工具。

具体使用:@DateTimeFormat(pattern="yyyy-MM-ddHH:mm:ss")

@Validated:用户参数校验,在需要校验的pojo后边添加BindingResult bindingResult接收校验出错信息

注意:@Validated和BindingResult bindingResult是配对出现,并且形参顺序是固定的(一前一后)

具体使用:(@Validated(McMerchantsDto.Add.class)McUserVo mcUserVo,BindingResult bindingResult)

@component :把普通pojo实例化到spring容器中,相当于配置文件中的

@JsonProperty:此注解用于属性上,作用是把该属性的名称序列化为另外一个名称,如把trueName属性序列化为name,@JsonProperty(value="name")

@JsonInclude(value=Include.NON_EMPTY)  是用再实体类的方法类的头上  作用是实体类的参数查询到的为null的不显示

你可能感兴趣的:(spring中相关注解)