Passing date to request param in Spring MVC

前端 未结 3 1860
醉话见心
醉话见心 2020-12-08 13:10

I am new to Spring MVC - and I am trying to pass a date from my javascript as a request Param

My controller looks something like -

public @ResponseB         


        
相关标签:
3条回答
  • 2020-12-08 13:30

    Use @DateTimeFormat("MMddyyyy")

    public @ResponseBody List<RecordDisplay> getRecords(
    @RequestParam(value="userID")  Long userID,
    @RequestParam(value="fromDate")     @DateTimeFormat(pattern="MMddyyyy") Date fromDate,
    @RequestParam(value="toDate")     @DateTimeFormat(pattern="MMddyyyy") Date toDate) {
    
    0 讨论(0)
  • 2020-12-08 13:48

    Use @DateTimeFormat(pattern="yyyy-MM-dd") where yyyy is year, MM is month and dd is date

    public @ResponseBody List<Student> loadStudents(@DateTimeFormat(pattern="yyyy-MM-dd") Date birthDay) {
        ...
    }
    
    0 讨论(0)
  • 2020-12-08 13:49

    This is now @DateTimeFormat as well which supports some common ISO formats

    0 讨论(0)
提交回复
热议问题