最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Mybatis-Plus主鍵插入null值報(bào)錯(cuò)問題及解決

 更新時(shí)間:2023年07月14日 14:45:32   作者:Win-ch  
這篇文章主要介紹了Mybatis-Plus主鍵插入null值報(bào)錯(cuò)問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Mybatis-Plus主鍵插入null值報(bào)錯(cuò)

Mysql數(shù)據(jù)庫主鍵對(duì)應(yīng)的實(shí)體類屬性id只要插入null

就會(huì)報(bào)如下錯(cuò)誤:

org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'id' of 'class com.entity.Student' with value '1281212463907368960' Cause: java.lang.IllegalArgumentException: argument type mismatch
### Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'id' of 'class com.entity.Student' with value '1281212463907368960' Cause: java.lang.IllegalArgumentException: argument type mismatch
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:57)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
    at com.sun.proxy.$Proxy5.save(Unknown Source)
    at com.baizhi.service.Impl.StudentServiceImpl.save(StudentServiceImpl.java:59)
    at Testdao.TestService(Testdao.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.apache.ibatis.reflection.ReflectionException: Could not set property 'id' of 'class com.entity.Student' with value '1281212463907368960' Cause: java.lang.IllegalArgumentException: argument type mismatch
    at org.apache.ibatis.reflection.wrapper.BeanWrapper.setBeanProperty(BeanWrapper.java:185)
    at org.apache.ibatis.reflection.wrapper.BeanWrapper.set(BeanWrapper.java:59)
    at org.apache.ibatis.reflection.MetaObject.setValue(MetaObject.java:140)
    at com.baomidou.mybatisplus.MybatisDefaultParameterHandler.populateKeys(MybatisDefaultParameterHandler.java:175)
    at com.baomidou.mybatisplus.MybatisDefaultParameterHandler.processBatch(MybatisDefaultParameterHandler.java:119)
    at com.baomidou.mybatisplus.MybatisDefaultParameterHandler.<init>(MybatisDefaultParameterHandler.java:79)
    at com.baomidou.mybatisplus.MybatisXMLLanguageDriver.createParameterHandler(MybatisXMLLanguageDriver.java:37)
    at org.apache.ibatis.session.Configuration.newParameterHandler(Configuration.java:532)
    at org.apache.ibatis.executor.statement.BaseStatementHandler.<init>(BaseStatementHandler.java:69)
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.<init>(PreparedStatementHandler.java:40)
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.<init>(RoutingStatementHandler.java:46)
    at org.apache.ibatis.session.Configuration.newStatementHandler(Configuration.java:545)
    at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)
    at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
    at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
    ... 28 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.ibatis.reflection.invoker.MethodInvoker.invoke(MethodInvoker.java:41)
    at org.apache.ibatis.reflection.wrapper.BeanWrapper.setBeanProperty(BeanWrapper.java:180)
    ... 43 more

經(jīng)過重重排除確定是Mysql的自增主鍵對(duì)應(yīng)的實(shí)體類屬性不能是null值,要想插入null值,需要在主鍵對(duì)應(yīng)的實(shí)體類屬性上加自增注解

?@TableId(type = IdType.AUTO)
? ? private Integer id;

(記錄一下使用Mybatis-Plus中碰到的坑,另外button會(huì)自動(dòng)提交表單一直刷新頁面,讓我的局部刷新操作失效,這兩個(gè)坑花了我大半個(gè)晚上解決。。。)

mybatis插入數(shù)據(jù)傳入值為null時(shí)提示無效的列類型

原因:mybatis無法解析值的類型

方法一

因?yàn)闊o法解析null為何種類型,可對(duì)傳入值在xml中指定類型,如下

<insert id="batchInsertQuestion" useGeneratedKeys="false">
? ? ? ? insert all
? ? ? ? <foreach collection="list" item="item" index="index">
? ? ? ? ? ? into ZB_APPRAISE_RECORD_QUESTION (id, record_id, question_name, sort_no, created_by, created_time,
? ? ? ? ? ? modified_by,
? ? ? ? ? ? modified_time,option_type,appraise_id)
? ? ? ? ? ? values
? ? ? ? ? ? (#{item.id},#{item.recordId},#{item.questionName,jdbcType=varchar},#{item.sortNo},#{item.createdBy},#{item.createdTime},#{item.modifiedBy},#{item.modifiedTime},#{item.optionType},#{item.appraiseId})
? ? ? ? </foreach>
? ? ? ? select 1 from dual
? ? </insert>

方法二

在mybatis-config.xml配置文件中配置:

<?xml version=”1.0” encoding=”UTF-8” ?>
<!DOCTYPE configuration PUBLIC “-//mybatis.org//DTD Config 3.0//EN” “http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
…
<settings>
<setting name="jdbcTypeForNull" value="NULL" />
</settings>
…
</configuration>

springboot yml配置方法如下

mybatis-plus:
? configuration:
? ? jdbc-type-for-null: 'null' #注意:單引號(hào)

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 一文帶你搞懂SpringBoot中自動(dòng)裝配原理

    一文帶你搞懂SpringBoot中自動(dòng)裝配原理

    這篇文章主要為大家詳細(xì)介紹了SpringBoot中自動(dòng)裝配原理的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,有需要的小伙伴可以參考下
    2025-01-01
  • SpringBoot整合Elasticsearch實(shí)現(xiàn)全文搜索功能

    SpringBoot整合Elasticsearch實(shí)現(xiàn)全文搜索功能

    在現(xiàn)代應(yīng)用程序中,對(duì)于大量數(shù)據(jù)的高效管理和快速檢索是至關(guān)重要的,Elasticsearch作為一款開源的全文搜索引擎,為開發(fā)者提供了強(qiáng)大而靈活的搜索解決方案,本文將介紹如何通過Spring Boot框架整合Elasticsearch,實(shí)現(xiàn)高效的全文搜索功能,需要的朋友可以參考下
    2025-12-12
  • Sentinel熱點(diǎn)key限流的實(shí)現(xiàn)詳解

    Sentinel熱點(diǎn)key限流的實(shí)現(xiàn)詳解

    這篇文章主要介紹了Sentinel熱點(diǎn)key限流的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • Java冪等性的4種解決方案實(shí)戰(zhàn)講解(附通俗案例)

    Java冪等性的4種解決方案實(shí)戰(zhàn)講解(附通俗案例)

    冪等性應(yīng)該是合格程序員的一個(gè)基因,在設(shè)計(jì)系統(tǒng)時(shí),是首要考慮的問題,尤其是在像支付寶,銀行,互聯(lián)網(wǎng)金融公司等涉及的都是錢的系統(tǒng),這篇文章主要介紹了Java冪等性的4種解決方案的相關(guān)資料,需要的朋友可以參考下
    2025-07-07
  • 完整的醫(yī)院就診掛號(hào)系統(tǒng)基于Spring MVC + Spring + MyBatis實(shí)現(xiàn)

    完整的醫(yī)院就診掛號(hào)系統(tǒng)基于Spring MVC + Spring + MyBatis實(shí)現(xiàn)

    這篇文章主要介紹了基于Spring MVC + Spring + MyBatis實(shí)現(xiàn)的醫(yī)院就診掛號(hào)系統(tǒng),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-08-08
  • 一文讀懂 Java 中的 ==、equals () 與 hashCode ()原理與避坑指南

    一文讀懂 Java 中的 ==、equals () 與 ha

    在 Java 開發(fā)中,==、equals()?和?hashCode()?是處理對(duì)象比較和哈希計(jì)算的核心元素,理解它們之間的區(qū)別與聯(lián)系對(duì)編寫高質(zhì)量代碼至關(guān)重要,本文給大家介紹Java 中的 ==、equals()與hashCode()原理,感興趣的朋友一起看看吧
    2025-09-09
  • Java設(shè)計(jì)模式常用原則解析

    Java設(shè)計(jì)模式常用原則解析

    這篇文章主要介紹了Java設(shè)計(jì)模式常用原則解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-05-05
  • 解決SpringBoot返回結(jié)果如果為null或空值不顯示處理問題

    解決SpringBoot返回結(jié)果如果為null或空值不顯示處理問題

    這篇文章主要介紹了解決SpringBoot返回結(jié)果如果為null或空值不顯示處理問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • springBoot基于webSocket實(shí)現(xiàn)掃碼登錄

    springBoot基于webSocket實(shí)現(xiàn)掃碼登錄

    最近做了個(gè)新項(xiàng)目,涉及到掃碼登錄。之前項(xiàng)目使用的是 ajax輪詢的方式。感覺太low了。所以這次用webSocket的方式進(jìn)行實(shí)現(xiàn),感興趣的可以了解一下
    2021-06-06
  • Java設(shè)計(jì)模式中的迭代器模式詳解

    Java設(shè)計(jì)模式中的迭代器模式詳解

    迭代器模式官方解釋就是提供一個(gè)對(duì)象來順序訪問聚合對(duì)象中的一系列數(shù)據(jù),而不暴露聚合對(duì)象的內(nèi)部表示。何為聚合對(duì)象呢?最典型的就是集合類。大白話也就是,集合中的數(shù)據(jù)是私有的,集合中不應(yīng)該提供直接遍歷的方法,要定義一個(gè)新的對(duì)象用于訪問這個(gè)集合
    2023-02-02

最新評(píng)論

乐至县| 阿拉善左旗| 吉首市| 黑山县| 株洲市| 永胜县| 郓城县| 奉节县| 壶关县| 滕州市| 天峨县| 佛冈县| 三穗县| 右玉县| 岳阳县| 大名县| 宁都县| 巴楚县| 开封市| 县级市| 新民市| 大关县| 体育| 株洲市| 潜江市| 赤城县| 杭锦后旗| 金湖县| 久治县| 盘山县| 平安县| 通道| 台安县| 阿图什市| 辉县市| 仁布县| 马尔康县| 兴义市| 濮阳市| 涟水县| 滦平县|