If I have serialized a class into json, which contains dates, using gson, how can I use the value of the json to insert into my h2 or MySQL database using MyBatis?
The json below is constructed using the following code:
Bean bean = new Bean();
bean.setIsPublished(true);
bean.setPublicationDate(Calendar.getInstance().getTime());
Gson gson = new GsonBuilder().setDateFormat("yyyy-mm-dd-hh:mm:ss").create();
String json = gson.toJson(bean);
Which makes json:
{
"isPublished":true,
"publicationDate":"2013-55-10-09:55:07"
}
But when I pass this json to my insert statement (using spring's @RequestBody to construct the Bean) the service returns a 400: Bad Syntax.
Here's the MyBatis Mapper's insert statement:
INSERT INTO beans (isPublished, publicationDate)
VALUES (#{isPublished}, parseDateTime(#{publicationDate}, 'yyyy-mm-dd-hh:mm:ss');
When I'm trying to insert the parsed json date, something is going wrong, but I'm not sure what.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…