{"id":6922,"date":"2022-08-18T21:24:26","date_gmt":"2022-08-18T13:24:26","guid":{"rendered":"http:\/\/123.57.164.21\/?p=6922"},"modified":"2022-08-18T21:54:58","modified_gmt":"2022-08-18T13:54:58","slug":"mybatis%e4%bb%80%e4%b9%88%e6%97%b6%e5%80%99%e9%9c%80%e8%a6%81%e6%b7%bb%e5%8a%a0jdbctype%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=6922","title":{"rendered":"Mybatis\u4ec0\u4e48\u65f6\u5019\u9700\u8981\u6dfb\u52a0\u201cjdbcType=\u6570\u636e\u7c7b\u578b\u201d"},"content":{"rendered":"\n<p>\u5728\u6267\u884cSQL\u65f6MyBatis\u4f1a\u81ea\u52a8\u901a\u8fc7\u5bf9\u8c61\u4e2d\u7684\u5c5e\u6027\u7ed9SQL\u4e2d\u53c2\u6570\u8d4b\u503c\uff0c\u5b83\u4f1a\u81ea\u52a8\u5c06Java\u7c7b\u578b\u8f6c\u6362\u6210\u6570\u636e\u5e93\u7684\u7c7b\u578b\u3002\u800c\u4e00\u65e6\u4f20\u5165\u7684\u662fnull\u5b83\u5c31\u65e0\u6cd5\u51c6\u786e\u5224\u65ad\u8fd9\u4e2a\u7c7b\u578b\u5e94\u8be5\u662f\u4ec0\u4e48\uff0c\u5c31\u6709\u53ef\u80fd\u5c06\u7c7b\u578b\u8f6c\u6362\u9519\u8bef\uff0c\u4ece\u800c\u62a5\u9519\u3002\u6240\u4ee5\u6211\u4eec\u8fd9\u6837\u505a\u3002<\/p>\n\n\n\n<p>\u7591\u95ee\u6765\u81ea\u4e8e\uff0c\u6709\u65f6\u5019Mapper.xml\u4e2d\uff0c\u4e0b\u9762\u90fd\u53ef\u4ee5\u7528\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">id = #{id,jdbcType=INTEGER}\n\nid = #{id}<\/pre>\n\n\n\n<p>\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff01<\/p>\n\n\n\n<p><strong>Mybatis\u4e2d\u4ec0\u4e48\u65f6\u5019\u5e94\u8be5\u58f0\u660ejdbcType\uff1f<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u4e24\u79cd\u5199\u6cd5\u90fd\u53ef\u4ee5\u3002\u5b83\u4eec\u90fd\u53ef\u4ee5\u83b7\u53d6Dao\u5c42\u4f20\u9012\u8fc7\u6765\u7684\u53c2\u6570\u3002<br>\u4f46\u662f\uff0c\u5f53\u4f20\u5165\u7684\u53c2\u6570\u4e3anull\u65f6\uff0c\u9700\u8981\u6307\u5b9ajdbcType\u7684\u7c7b\u578b,\u5426\u5219mybatis\u65e0\u6cd5\u89e3\u6790\u3002<\/pre>\n\n\n\n<p>#{property, jdbcType=VARCHAR}<br>\u5982\u679c\u4e00\u4e2a\u5217\u5141\u8bb8 null \u503c\uff0c\u5e76\u4e14\u4f1a\u4f20\u9012\u503c null \u7684\u53c2\u6570\uff0c\u5c31\u5fc5\u987b\u8981\u6307\u5b9a JDBC Type<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u4e00\u4e2a\u53ef\u4ee5\u4e3anull\u7684\u5b57\u6bb5\uff0c\u5728insert\u7684\u65f6\u5019\uff0c\u6ca1\u6709\u7ed9\u8be5\u5b57\u6bb5\u8d4b\u503c\uff0cmybatis\u5c31\u4f1a\u62a5\u4e0b\u9762\u7684\u9519\u8bef<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='__frch_item_0.defaultValue', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #6 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: \u65e0\u6548\u7684\u5217\u7c7b\u578b: 1111\n\tat org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)\n \nCaused by: org.apache.ibatis.type.TypeException: Error setting null for parameter #6 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: \u65e0\u6548\u7684\u5217\u7c7b\u578b: 1111\n\tat org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:47)\n\tat org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:87)\n\t... 54 more\nCaused by: java.sql.SQLException: \u65e0\u6548\u7684\u5217\u7c7b\u578b: 1111<\/pre>\n\n\n\n<p>\u5f53Mybatis\u4e0d\u80fd\u81ea\u52a8\u8bc6\u522b\u4f60\u4f20\u5165\u5bf9\u8c61\u7684\u7c7b\u578b\u65f6\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/08\/image-5-1024x64.png\" alt=\"\" class=\"wp-image-6925\" width=\"674\" height=\"42\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/08\/image-5-1024x64.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/08\/image-5-300x19.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/08\/image-5-768x48.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/08\/image-5-830x52.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/08\/image-5-230x14.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/08\/image-5-350x22.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/08\/image-5-480x30.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/08\/image-5.png 1374w\" sizes=\"(max-width: 674px) 100vw, 674px\" \/><\/figure><\/div>\n\n\n\n<p>\u6240\u4ee5\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9700\u8981\u9488\u5bf9\u8fd9\u4e9b\u53ef\u80fd\u4e3a\u7a7a\u7684\u5b57\u6bb5\uff0c\u624b\u52a8\u6307\u5b9a\u5176\u8f6c\u6362\u65f6\u7528\u5230\u7684\u7c7b\u578b\u3002<\/p>\n\n\n\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u6ca1\u6709\u5fc5\u8981\u6309\u4e2a\u5b57\u6bb5\u53bb\u8bc6\u522b\/\u5224\u65ad\u5b83\u662f\u5426\u53ef\u4ee5\u4e3a\u7a7a\uff0c\u800c\u662f\u5c06\u6240\u6709\u7684\u5b57\u6bb5\u90fd\u5f53\u505a\u53ef\u4ee5\u4e3a\u7a7a\uff0c\u5168\u90e8\u624b\u52a8\u8bbe\u7f6e\u8f6c\u6362\u7c7b\u578b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;update id=\"updateByPrimaryKey\" parameterType=\"com.funyan.User\" >    \nupdate user    \nset user_name = #{userName,jdbcType=VARCHAR},    \nuser_pass = #{userPass,jdbcType=VARCHAR},    \nuser_nickname = #{userNickname,jdbcType=VARCHAR},    \nuser_email = #{userEmail,jdbcType=VARCHAR},    \nuser_url = #{userUrl,jdbcType=VARCHAR},    \nuser_avatar = #{userAvatar,jdbcType=VARCHAR},    \nuser_last_login_ip = #{userLastLoginIp,jdbcType=VARCHAR},    \nuser_register_time = #{userRegisterTime,jdbcType=TIMESTAMP},    \nuser_last_login_time = #{userLastLoginTime,jdbcType=TIMESTAMP},    \nuser_status = #{userStatus,jdbcType=INTEGER}    \nwhere user_id = #{userId,jdbcType=INTEGER}    \n&lt;\/update><\/pre>\n\n\n\n<p>\u9644\uff1a<strong>Mybatis\u4e2d javaType \u548c jdbcType \u5bf9\u5e94\u5173\u7cfb<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">JDBCType            JavaType\nCHAR                String\nVARCHAR             String\nLONGVARCHAR         String\nNUMERIC             java.math.BigDecimal\nDECIMAL             java.math.BigDecimal\nBIT                 boolean\nBOOLEAN             boolean\nTINYINT             byte\nSMALLINT            short\nINTEGER             int\nBIGINT              long\nREAL                float\nFLOAT               double\nDOUBLE              double\nBINARY              byte[]\nVARBINARY           byte[]\nLONGVARBINARY               byte[]\nDATE                java.sql.Date\nTIME                java.sql.Time\nTIMESTAMP           java.sql.Timestamp\nCLOB                Clob\nBLOB                Blob\nARRAY               Array\nDISTINCT            mapping of underlying type\nSTRUCT              Struct\nREF                 Ref\nDATALINK            java.net.URL<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u6267\u884cSQL\u65f6MyBatis\u4f1a\u81ea\u52a8\u901a\u8fc7\u5bf9\u8c61\u4e2d\u7684\u5c5e\u6027\u7ed9SQL\u4e2d\u53c2\u6570\u8d4b\u503c\uff0c\u5b83\u4f1a\u81ea\u52a8\u5c06Java\u7c7b\u578b\u8f6c\u6362\u6210\u6570\u636e\u5e93\u7684\u7c7b\u578b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6922"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6922"}],"version-history":[{"count":4,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6922\/revisions"}],"predecessor-version":[{"id":6928,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6922\/revisions\/6928"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}