spring 用过的注解 01

注意:需要和对象前面的注解 @validated  一起使用  或者 @valid 一起使用  

@Pattern()  注解 

正则表达式的校验 : 校验规则: regexp=“规则” 

@NotBlank(message = "项目标识符不得为空")
@Pattern(regexp = "[a-z0-9_\\-]{1,100}", message = "仅小写字母(a-z)、数字、破折号(-)和下划线(_)可以使用,且长度最长为100,最短为1")
    private String identifier;

用法 :  

https://blog.csdn.net/Vincent2014Linux/article/details/105972676

https://blog.csdn.net/qq_36927265/article/details/87864026

https://my.oschina.net/fxtxz2/blog/1859600

 

@NotBlank(message = "项目标识符不得为空")

@NotEmpty

@notNull

 非空检查注解  , 区别:

@NotEmpty 用在集合类上面
加了@NotEmpty的String类、Collection、Map、数组,是不能为null或者长度为0的(String Collection Map的isEmpty()方法)

@NotBlank只用于String,不能为null且trim()之后size>0

@NotNull:不能为null,但可以为empty,没有Size的约束   用在基本类型上

注意:需要和对象前面的注解 @validated  一起使用  或者 @valid 一起使用  ,让他们生效 

为了便于理解:

String name = null;
@NotNull: false
@NotEmpty: false
@NotBlank: false

String name = "";
@NotNull: true
@NotEmpty: false
@NotBlank: false

String name = " ";
@NotNull: true
@NotEmpty: true
@NotBlank: false     \\ 这个会trim 一下字符串 ,就是去除空格的意思 

String name = "Great answer!";
@NotNull: true
@NotEmpty: true
@NotBlank: true

来源 :

https://blog.csdn.net/zZ_life/article/details/51470909

下边这个可以好好看一看  

https://www.cnblogs.com/xinglongbing521/p/10299414.html
 

@JsonFormat与@DateTimeFormat

出参格式化  :  后端到前端

@JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")

   pattern:是你需要转换的时间日期的格式

   timezone:是时间设置为东八区,避免时间在转换中有误差

入参格式化 : 前端到后端  

 @DateTimeFormat 

来源 :  

https://my.oschina.net/u/3358860/blog/3028788

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值