我的朋友,
我上课了......
@NotBlank(message = "timesheet.cadastro.horainicio.obrigatorio")
@Temporal(TemporalType.TIME)
@Column(name = "INICIO", nullable = false)
private Date horaInicio;
并且,在我的测试(groovy)中,我将null放到"horaInicio":
def "Salvar um timesheet sem hora inicio"() {
    given:"um timesheet sem data"
        def usuario = sessionFactory.getCurrentSession().get(Usuario.class,1L) as Usuario
        def dias = sessionFactory.getCurrentSession().get(Dias.class,1L) as Dias
        def timeSheet = criarTimeSheet(usuario,dias) as TimeSheet
        timeSheet.horaInicio = null
    when:"buscar na base"
        def timeSheetPersistido = timeSheetService.salvar(timeSheet)
    then:"retorna uma lista de timesheet"
        def erro = thrown(ConstraintViolationException)
        "timesheet.cadastro.horainicio.obrigatorio".equals(erro.getConstraintViolations().asList().get(0).getMessage())
}
但我有错误:
Expected exception javax.validation.ConstraintViolationException, but got javax.validation.UnexpectedTypeException
    at org.spockframework.lang.SpecInternals.thrownImpl(SpecInternals.java:79)
    at br.com.infowhere.service.TimeSheetServiceIt.Salvar um timesheet sem hora inicio(TimeSheetServiceIt.groovy:80)
Caused by: javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.util.Date.
有人可以帮帮我吗?
谢谢
Mik*_*unu 30
正如文档中所述,@ NotBlank用于String类型.没有java.util.Date的概念为空.它可以为null或不为null.
验证带注释的字符串不为null或为空.与NotEmpty的区别在于尾随空格被忽略.
如果目标是检查值是否为null,则应使用@NotNull.根据文件:
带注释的元素不能为null.接受任何类型.
| 归档时间: | 
 | 
| 查看次数: | 26138 次 | 
| 最近记录: |