gpt4 book ai didi

java - 找不到类型 : java. lang.Long :No validator could be found for type: java. lang.Long 的 validator

转载 作者:行者123 更新时间:2023-11-30 02:27:22 24 4
gpt4 key购买 nike

我有一个对象类,除了 Id 之外没有必填字段。这是代码:

Entity
@XmlRootElement
@Table(name = "T_HOST_SPEC")
@Cacheable(false)
@NamedQueries({
@NamedQuery(name = HostSpec.FIND_ALL, query = "SELECT m FROM HostSpec m")
,@NamedQuery(name = HostSpec.FIND_BY_IP_CONTEXT_PATH_PORT, query = "SELECT m FROM HostSpec m WHERE m.ip = :ip AND m.contextPath =:contextPath AND m.port =:port ")})
public class HostSpec extends AbstractEntity {



@Id
@SequenceGenerator(name = "HOST_SPEC_SEQUENCE_GENERATOR", sequenceName = "HOST_SPEC_SEQ", initialValue = 1, allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HOST_SPEC_SEQUENCE_GENERATOR")
@XmlElement(name = "id")
@NotNull
@Column(name = "ID", nullable = false)
private Long id;

@Size(max =200 )
@Column(name = "APP_NAME",length = 25)
@XmlElement(name = "APP_NAME")
private String appName;

@Size(max =1000 )
@Column(name = "APP_SERVER_INFO",length = 25)
@XmlElement(name = "APP_SERVER_INFO")
private String serverInfo;

@Size(max =100 )
@Column(name = "CONTEXT_PATH",length = 25)
@XmlElement(name = "CONTEXT_PATH")
private String contextPath;

@Size(max =255 )
@Column(name = "BUILD_DATE",length = 25)
@XmlElement(name = "BUILD_DATE")
private String buildDate;

@Size(max =4000 )
@Column(name = "DESCRIPTION",length = 25)
@XmlElement(name = "DESCRIPTION")
private String description;


@Size(max =50 )
@Column(name = "IP",length = 25)
@XmlElement(name = "IP")
private String ip;

@Size(max =200 )
@Column(name = "MODULE_NAME",length = 25)
@XmlElement(name = "MODULE_NAME")
private String moduleName;

@Size(max =100 )
@Column(name = "NAME",length = 25)
@XmlElement(name = "NAME")
private String name;

@Size(max = 10)
@XmlElement(name = "PORT")
@Column(name = "PORT")
private Long port;

@Size(max =20 )
@Column(name = "PROTOCOL",length = 25)
@XmlElement(name = "PROTOCOL")
private String protocol;


@Size(max = 10)
@XmlElement(name = "VERSION_CODE")
@Column(name = "VERSION_CODE")
private Long versionCode;

@Size(max =100 )
@Column(name = "VERSION_NAME",length = 25)
@XmlElement(name = "VERSION_NAME")
private String versionName;

@Size(max =100 )
@Column(name = "VIRTUAL_SERVER_NAME",length = 25)
@XmlElement(name = "VIRTUAL_SERVER_NAME")
private String serverName;

//getters & setters

当我尝试运行它时,抛出此异常:javax.validation.UnexpectedTypeException:HV000030:找不到类型的 validator :java.lang.Long请帮忙

最佳答案

@Size 不适用于 Long 类型(在这种情况下,您应使用 @Max)。

因此,您应该将 portversionCode 字段上的 @Size(max = 10) 替换为相应的 @Max 注释

根据 javadoc,@Size 可用于以下类型:

  • 字符串(评估字符串长度)
  • 集合(评估集合大小)
  • map (评估 map 大小)
  • 数组(计算数组长度)
  • null 元素被视为有效。

关于java - 找不到类型 : java. lang.Long :No validator could be found for type: java. lang.Long 的 validator ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45299852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com