小编use*_*612的帖子

验证器出错(找不到类型为:java.util.Date的验证器.)

我的朋友,

我上课了......

@NotBlank(message = "timesheet.cadastro.horainicio.obrigatorio")
@Temporal(TemporalType.TIME)
@Column(name = "INICIO", nullable = false)
private Date horaInicio;
Run Code Online (Sandbox Code Playgroud)

并且,在我的测试(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())
}
Run Code Online (Sandbox Code Playgroud)

但我有错误:

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 …
Run Code Online (Sandbox Code Playgroud)

hibernate

9
推荐指数
1
解决办法
3万
查看次数

带有日期的Spring MVC控制器

我一直在尝试使用:

@RequestMapping(value="/consultaporusuarioperiodo/{idusuario}/{datainicio}/{datafim}", method = RequestMethod.GET)
public String consultaPorPeriodoUsuario(
        @PathVariable("idusuario") Long idUsuario,
        @PathVariable("datainicio") Date dataInicio,
        @PathVariable("datafim") Date dataFim
        ,Model model) {
    Usuario usuario = usuarioService.buscaPorId(idUsuario);
    model.addAttribute("timesheet",timeSheetService.buscaPorPeriodoPorUsuario(dataInicio, dataFim,usuario));
    return "timesheetcrud/consultatimesheet";
}
Run Code Online (Sandbox Code Playgroud)

有了这个链接:

http://localhost:8080/timesheet/consultaporusuarioperiodo/1/21012000/22012000
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:

HTTP Status 400 -

type Status report

message

description The request sent by the client was syntactically incorrect ().

Apache Tomcat/7.0.27
Run Code Online (Sandbox Code Playgroud)

当我改为:

        @PathVariable("datainicio") String dataInicio,
        @PathVariable("datafim") String dataFim
Run Code Online (Sandbox Code Playgroud)

这是工作.使用Date可以做些什么?

谢谢

java spring spring-mvc

6
推荐指数
2
解决办法
1万
查看次数

spring mvc中的转换数据类型

我的Spring MVC有问题.

@RequestMapping(value = "/novo", method = RequestMethod.GET)
public ModelAndView novoTimeSheet() {
    return new ModelAndView("timesheetcrud/novo", "timesheet", new TimeSheet());
}
Run Code Online (Sandbox Code Playgroud)

我的TimeSheet班级有:

@NotNull(message = "timesheet.cadastro.horainicio.obrigatorio")
@Temporal(TemporalType.TIME)
@Column(name = "INICIO", nullable = false)
private Date horaInicio;

@NotNull(message = "timesheet.cadastro.horafim.obrigatorio")
@Temporal(TemporalType.TIME)
@Column(name = "FIM", nullable = false)
private Date horaFim;
Run Code Online (Sandbox Code Playgroud)

我的addTimeSheet:

@RequestMapping(value = "/addtimesheet", method = RequestMethod.POST)
public String addTimeSheet(@ModelAttribute("timesheet")TimeSheet timeSheet,
                         ModelMap model) {
Run Code Online (Sandbox Code Playgroud)

在浏览器中,当我放置不相等的日期时,我有这个错误:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object …
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc

4
推荐指数
1
解决办法
1万
查看次数

'one to many'属性值类型不应该是'persistence entity'

我有1个用户到多个其他域并将其放在我的代码中:

用户类

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotBlank;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

@Entity
@Table(name = "USUARIO")
public class Usuario {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID_USUARIO",unique = true,nullable = false)
    private Long id;

    @NotBlank(message = "usuario.cadastro.nome.obrigatorio")
    @Column(name = "NOME", unique = true, nullable = false,length = 100)
    private String nome;

    @Email(message = "usuario.cadastro.email.invalido")
    @Column(name = …
Run Code Online (Sandbox Code Playgroud)

hibernate

3
推荐指数
2
解决办法
1万
查看次数

标签 统计

hibernate ×2

spring ×2

spring-mvc ×2

java ×1