使用Spring Rest Service时,在Date中获得错误的月份错误

时间:2022-10-28 21:53:42

I am using spring rest services. I am getting wrong month when the json is parsed by Spring

我正在使用春季休息服务。当json被Spring解析时,我错了一个月

to : Fri Jan 13 05:30:00 IST 2017 from : Sat Jan 14 05:30:00 IST 2017

to:Fri Jan 13 05:30:00 IST 2017 from:Jan Jan 14 05:30:00 IST 2017

I am not even passing the time also time is not as my system clock.

我甚至没有打发时间也不是我的系统时钟。

This is my json request

这是我的json请求

{"emp_name":"Pavan Keely","emp_id":"135835","entry_by":"172033","is_half_day":false,"applied_to_date":"13/02/2017","applied_from_date":"14/02/2017","taken_to_date":"","taken_from_date":"","leave_type_id":"1"}

This is POJO class

这是POJO类

public class AppliedLeave
{

private int id;
private String emp_id;
private int leave_type_id;
@JsonFormat(pattern="dd/MM/yyyy")
private Date applied_from_date;
@JsonFormat(pattern="dd/MM/yyyy")
private Date applied_to_date;
private boolean is_half_day;
private double no_of_days_applied;
private String entry_by;
private String entry_date;
}

Assume getter setter are there

假设getter setter在那里

And this is my controller

这是我的控制者

@RequestMapping(value = "/add-taken-leave", method = RequestMethod.POST)
public ResponseEntity<String> addTakenLeave(@RequestBody TakenLeave takenLeave)
{
    if ((leaveTrackerService.addTakenLeave(takenLeave)).equals("success"))
        return new ResponseEntity<String>("{\"success\": \"true\" }",        HttpStatus.OK);
    return new ResponseEntity<String>("{\"success\": \"false\" }", HttpStatus.OK);
}

1 个解决方案

#1


0  

Try to use @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="dd/MM/yyyy") instead.

尝试使用@JsonFormat(shape = JsonFormat.Shape.STRING,pattern =“dd / MM / yyyy”)代替。

#1


0  

Try to use @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="dd/MM/yyyy") instead.

尝试使用@JsonFormat(shape = JsonFormat.Shape.STRING,pattern =“dd / MM / yyyy”)代替。