首页>代码>Java Bean Validation和Hibernate Validation简单使用实例,支持自定义标注实现验证功能>/java-bean-validation/src/main/java/com/hellokoding/validation/Product.java
package com.hellokoding.validation;

import javax.validation.constraints.*;
import java.math.BigDecimal;

public class Product {
    @NotNull
    private Long id;

    @ProductCodeExisting
    private String code;

    @Size(min = 1, max = 10, message = "{Size.name}")
    private String name;

    @NotNull(message = "must be not null")
    private String description;

    @Min(value = 1, message = "{Min.price}")
    private BigDecimal price;

    @Pattern(regexp = "http(s)?://(www)?\\.(.*?)\\.(.*?)")
    private String domain;

    @Email
    private String email;

    public Product(Long id, String code, String name, String description, BigDecimal price, String domain, String email) {
        this.id = id;
        this.code = code;
        this.name = name;
        this.description = description;
        this.price = price;
        this.domain = domain;
        this.email = email;
    }
}
最近下载更多
BestClever  LV32 2020年10月19日
最代码官方  LV168 2020年10月18日
最近浏览更多
幸运疯子  LV13 2021年5月16日
760632 2021年4月9日
暂无贡献等级
1771658781  LV5 2020年12月25日
pxqtsht  LV16 2020年11月24日
me0001 2020年11月19日
暂无贡献等级
jiuzhoupiaoping  LV2 2020年11月17日
kobe729  LV5 2020年11月13日
LikL9420  LV12 2020年10月30日
wsdxdll 2020年10月28日
暂无贡献等级
忘久久  LV3 2020年10月24日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友