{"id":25678,"date":"2024-11-24T13:45:13","date_gmt":"2024-11-24T05:45:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25678\/"},"modified":"2024-11-24T13:45:13","modified_gmt":"2024-11-24T05:45:13","slug":"springboot-%e4%b8%ad%e5%a6%82%e4%bd%95%e6%9f%a5%e8%af%a2-mysql-date-%e7%b1%bb%e5%9e%8b%e6%97%a5%e6%9c%9f%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25678\/","title":{"rendered":"SpringBoot \u4e2d\u5982\u4f55\u67e5\u8be2 MySQL DATE \u7c7b\u578b\u65e5\u671f\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173068092381643.jpg\" class=\"aligncenter\" title=\"SpringBoot \u4e2d\u5982\u4f55\u67e5\u8be2 MySQL DATE \u7c7b\u578b\u65e5\u671f\uff1f\u63d2\u56fe\" alt=\"SpringBoot \u4e2d\u5982\u4f55\u67e5\u8be2 MySQL DATE \u7c7b\u578b\u65e5\u671f\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>SpringBoot \u4e2d\u67e5\u8be2 MySQL DATE \u7c7b\u578b\u65e5\u671f<\/strong><\/p>\n<p>\u5728 SpringBoot \u4e2d\uff0c\u5bf9\u4e8e\u65e5\u671f\u65f6\u95f4\u5904\u7406\uff0c\u901a\u5e38\u4f1a\u51fa\u73b0\u4ece\u524d\u7aef\u5230\u540e\u7aef\u518d\u5230\u6570\u636e\u5e93\u7684\u8f6c\u6362\u95ee\u9898\u3002\u6211\u4eec\u4ee5\u4e00\u4e2a\u5e38\u89c1\u7684\u573a\u666f\u4e3a\u4f8b\uff0c\u63a2\u8ba8\u5982\u4f55\u67e5\u8be2 MySQL \u4e2d\u7684 DATE \u7c7b\u578b\u5b57\u6bb5\u3002<\/p>\n<p>\u5728\u793a\u4f8b\u4ee3\u7801\u4e2d\uff0c\u524d\u7aef\u53c2\u6570 lessonDate \u4f7f\u7528 @DateTimeFormat \u6ce8\u89e3\uff0c\u6307\u5b9a\u65e5\u671f\u683c\u5f0f\u4e3a &#8220;yy-MM-dd&#8221;\u3002\u6839\u636e\u8fd9\u4e2a\u683c\u5f0f\uff0c\u540e\u7aef\u63a5\u6536\u65f6\u4f1a\u81ea\u52a8\u8f6c\u6362\u4e3a Date \u5bf9\u8c61\uff0c\u7136\u540e\u53c8\u81ea\u52a8\u8f6c\u6362\u4e3a Timestamp \u5bf9\u8c61\uff0c\u6700\u7ec8\u5b58\u50a8\u5230 MySQL \u4e2d\u3002<\/p>\n<p>\u7531\u4e8e MySQL \u4e2d\u7684 lessonDate \u5b57\u6bb5\u662f DATE \u7c7b\u578b\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u53ea\u5305\u542b\u65e5\u671f\u90e8\u5206\uff0c\u4e0d\u5305\u542b\u65f6\u95f4\u90e8\u5206\u3002\u800c Timestamp \u5bf9\u8c61\u5305\u542b\u4e86\u65e5\u671f\u548c\u65f6\u95f4\u4fe1\u606f\uff0c\u56e0\u6b64\u5728\u67e5\u8be2\u65f6\u4f1a\u4ea7\u751f\u7c7b\u578b\u4e0d\u5339\u914d\u7684\u95ee\u9898\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\u662f\uff0c\u5728\u540e\u7aef\u63a5\u6536\u65e5\u671f\u65f6\u76f4\u63a5\u4f7f\u7528 String \u7c7b\u578b\uff0c\u800c\u4e0d\u662f Date \u6216 Timestamp\u3002\u8fd9\u5c06\u907f\u514d\u81ea\u52a8\u8f6c\u6362\uff0c\u5e76\u5141\u8bb8\u6211\u4eec\u76f4\u63a5\u6309\u9884\u671f\u683c\u5f0f\u67e5\u8be2 MySQL \u4e2d\u7684 DATE \u7c7b\u578b\u5b57\u6bb5\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fSpringBoot \u4e2d\u5982\u4f55\u67e5\u8be2 MySQL DATE \u7c7b\u578b\u65e5\u671f\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SpringBoot \u4e2d\u67e5\u8be2 MySQL DATE \u7c7b\u578b\u65e5\u671f \u5728 SpringBoot \u4e2d\uff0c\u5bf9\u4e8e\u65e5\u671f\u65f6\u95f4\u5904\u7406\uff0c\u901a\u5e38\u4f1a\u51fa\u73b0\u4ece\u524d\u7aef\u5230\u540e\u7aef\u518d\u5230\u6570\u636e\u5e93\u7684\u8f6c\u6362\u95ee\u9898\u3002\u6211\u4eec\u4ee5\u4e00\u4e2a\u5e38\u89c1\u7684\u573a\u666f\u4e3a\u4f8b\uff0c\u63a2\u8ba8\u5982\u4f55\u67e5\u8be2 MySQL \u4e2d\u7684 DATE \u7c7b\u578b\u5b57\u6bb5\u3002 \u5728\u793a\u4f8b\u4ee3\u7801\u4e2d\uff0c\u524d\u7aef\u53c2\u6570 lessonDate \u4f7f\u7528 @DateTimeFormat \u6ce8\u89e3\uff0c\u6307\u5b9a\u65e5\u671f\u683c\u5f0f\u4e3a &#8220;yy-MM-dd&#8221;\u3002\u6839\u636e\u8fd9\u4e2a\u683c\u5f0f\uff0c\u540e\u7aef\u63a5\u6536\u65f6\u4f1a\u81ea\u52a8\u8f6c\u6362\u4e3a Date \u5bf9\u8c61\uff0c\u7136\u540e\u53c8\u81ea\u52a8\u8f6c\u6362\u4e3a Timestamp \u5bf9\u8c61\uff0c\u6700\u7ec8\u5b58\u50a8\u5230 MySQL \u4e2d\u3002 \u7531\u4e8e MySQL \u4e2d\u7684 lessonDate \u5b57\u6bb5\u662f DATE \u7c7b\u578b\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u53ea\u5305\u542b\u65e5\u671f\u90e8\u5206\uff0c\u4e0d\u5305\u542b\u65f6\u95f4\u90e8\u5206\u3002\u800c Timestamp \u5bf9\u8c61\u5305\u542b\u4e86\u65e5\u671f\u548c\u65f6\u95f4\u4fe1\u606f\uff0c\u56e0\u6b64\u5728\u67e5\u8be2\u65f6\u4f1a\u4ea7\u751f\u7c7b\u578b\u4e0d\u5339\u914d\u7684\u95ee\u9898\u3002 \u89e3\u51b3\u65b9\u6cd5\u662f\uff0c\u5728\u540e\u7aef\u63a5\u6536\u65e5\u671f\u65f6\u76f4\u63a5\u4f7f\u7528 String \u7c7b\u578b\uff0c\u800c\u4e0d\u662f Date \u6216 Timestamp\u3002\u8fd9\u5c06\u907f\u514d\u81ea\u52a8\u8f6c\u6362\uff0c\u5e76\u5141\u8bb8\u6211\u4eec\u76f4\u63a5\u6309\u9884\u671f\u683c\u5f0f\u67e5\u8be2 MySQL \u4e2d\u7684 DATE \u7c7b\u578b\u5b57\u6bb5\u3002 \u4ee5\u4e0a\u5c31\u662fSpringBoot \u4e2d\u5982\u4f55\u67e5\u8be2 MySQL DATE \u7c7b\u578b\u65e5\u671f\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-25678","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=25678"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25678\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}