Spring converting String to date or calendar in Pathparam / Queryparam / RequestParam

Spring converting String to date in Spring controller:

Send a date in YYYY-MM-DD format to a Spring Controller. Write a proper converter for that object, controller will able to hadle request.

Example of Converting string to date object with   Pathparam / Queryparam / RequestParam:

@RequestMapping(value="/fetch" , method=RequestMethod.GET)
 public @ResponseBody String fetchResult(@RequestParam("date") @DateTimeFormat(pattern="yyyy-MM-dd") Date date) {
        //Content goes here
}

@RequestMapping(value="/fetch/{date}" , method=RequestMethod.GET)
 public @ResponseBody String fetchResult(@PathParam("date") @DateTimeFormat(pattern="yyyy-MM-dd") Date date) {
        //Content goes here
}

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation