springcloud中一些注解解释

@Data

自动增加包括get/set方法,tostring,equal,hashcode。

@Entity

对实体注释,任何hibernate映射对想都要有这个注释,指明这是一个实体bean。

@Table

声明此对象映射到数据库的数据表,通过他可以为实体指定表,目录和schema的名字,该注释不是必须的,如果没有则系统使用默认值(实体的短类名)。

@Column

声明该属性与数据库字段的映射关系。

@ApiOperation(value = “接口说明”, httpMethod = “接口请求方式”, response = “接口返回参数类型”, notes = “接口发布说明”;其他参数可参考源码; 接口描述。

@ApiParam(required = “是否必须参数”, name = “参数名称”, value = “参数具体描述”

实际项目中非常需要写文档,提高Java服务端和Web前端以及移动端的对接效率。

Swagger是当前最好用的Restful API文档生成的开源项目,通过swagger-spring项目

实现了与SpingMVC框架的无缝集成功能,方便生成spring restful风格的接口文档,

同时swagger-ui还可以测试spring restful风格的接口功能。

@NoArgsConstructor : 生成一个无参数的构造方法,这个annotation在与其他的annotation配合起来使用的时候更加能凸显出他的重要性,例如在使用hibernate这种框架的时候,如果有一个有参数的构造方法的时候,NoArgsConstructor会展示出他的作用。

生成无参构造方法

@AllArgsContructor:  会生成一个包含所有变量,同时如果变量使用了NotNull annotation , 会进行是否为空的校验, 我们来看一下官方给出的一个例子:

import lombok.AccessLevel;

import lombok.RequiredArgsConstructor;

import lombok.AllArgsConstructor;

import lombok.NonNull;

 

@RequiredArgsConstructor(staticName = "of")

@AllArgsConstructor(access = AccessLevel.PROTECTED)

public class ConstructorExample<T> {

  private int x, y;

  @NonNull private T description;

  

  @NoArgsConstructor

  public static class NoArgsExample {

    @NonNull private String field;

  }

}

 

 

 

用java翻译一下就是这个意思:

public class ConstructorExample<T> {

  private int x, y;

  @NonNull private T description;

  

  private ConstructorExample(T description) {

    if (description == null) throw new NullPointerException("description");

    this.description = description;

  }

  

  public static <T> ConstructorExample<T> of(T description) {

    return new ConstructorExample<T>(description);

  }

  

  @java.beans.ConstructorProperties({"x", "y", "description"})

  protected ConstructorExample(int x, int y, T description) {

    if (description == null) throw new NullPointerException("description");

    this.x = x;

    this.y = y;

    this.description = description;

  }

  

  public static class NoArgsExample {

    @NonNull private String field;

    public NoArgsExample() {

    }

  }

}

 

 

@EnableSwagger2

加了这个注解就可以在这个页面里面看见响应类下面的响应接口。

swagger的出现就是为了方便进行测试后台的restful形式的接口,实现动态的更新,当我们在后台的接口修改了后,swagger可以实现自动的更新,而不需要认为的维护这个接口进行测试。

 

如需详细了解swagger可以查看下面两个链接:

https://www.cnblogs.com/fengli9998/p/7522973.html

http://www.cnblogs.com/h9527/p/5506956.html

 

@EnableCaching

开启缓存,完成一些简单的缓存功能。

@WebFilter:过滤器

@Componet:定义spring管理bean

@EnableScheduling:启用定时任务

@Configuration

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

@Repository用于标注数据访问组件,即DAO组件;可以标记在任何的类上,用来表明该类是用来执行与数据库相关的操作(即dao对象),并支持自动处理数据库操作产生的异常

@Component是通用注解,其他三个注解是这个注解的拓展,并且具有了特定的功能 
@Repository注解在持久层中,具有将数据库操作抛出的原生异常翻译转化为spring的持久层异常的功能。 
@Controller层是spring-mvc的注解,具有将请求进行转发,重定向的功能。 
@Service层是业务逻辑层注解,这个注解只是标注该类处于业务逻辑层。 

关于这三个注解的更多解释,可查看:

https://blog.csdn.net/fansili/article/details/78740877

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值