I've been trying to use:
@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";
}
with this link:
http://localhost:8080/timesheet/consultaporusuarioperiodo/1/21012000/22012000
but I get this error:
HTTP Status 400 -
type Status report
message
description The request sent by the client was syntactically incorrect ().
Apache Tomcat/7.0.27
when I change to:
@PathVariable("datainicio") String dataInicio,
@PathVariable("datafim") String dataFim
It's work. What can I do to work with Date ?
thanks
Try:
@PathVariable("datainicio") @DateTimeFormat(iso=ISO.DATE) String dataInicio,
@PathVariable("datafim") @DateTimeFormat(iso=ISO.DATE) String dataFim
where ISO.DATE
is of yyyy-mm-dd
pattern.
I had to do something very similar. This is what I did:
@PathVariable("datainicio") @DateTimeFormat(pattern = "ddMMyyyy") Date dataInicio
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With