The springboot get request receives a date type parameter

Time:2021-7-8
The front-end transfers the time directly. If the back-end receives the parameter directly without processing, an exception will appear. Use the annotation @ datetimeformat to solve the problem

problem

@RequestMapping(value="/fetch" , method=RequestMethod.GET)
public @ResponseBody String fetchResult(@RequestParam("from") Date fromDate) {
        //Content goes here
}

Treatment method

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

@RequestParam()It can be omitted, but the parameter name needs to be consistent with the custom received parameter.

This work adoptsCC agreementReprint must indicate the author and the link of this article

Recommended Today

Build HTTP service with C + + Mongoose

Mongoose source code address:https://github.com/cesanta/mo… Mongoose user manual:https://www.cesanta.com/devel… Mngoose set up HTTP service #include <string> #include “mongoose.h” using namespace std; static const char *s_http_port = “8000”; static void ev_handler(mg_connection *nc, int ev, void *ev_data) { struct http_message *hm = (struct http_message *) ev_data; if (ev == MG_EV_HTTP_REQUEST) { std::string uri; if (hm->uri.p && hm->uri.p[0] == ‘/’) […]