美文网首页
Spring_boot中Mybatis存储过程中出现的错误及修改

Spring_boot中Mybatis存储过程中出现的错误及修改

作者: 俊兮 | 来源:发表于2019-03-28 19:08 被阅读0次

    刚交接到这个项目,也是初次使用Spring_boot框架。

    前工作人员工作经历不是太深,所以,这是我修改他所留下来的问题做一次总结

    【】错误一

    2019-03-28 16:39:47.687 DEBUG 51096 --- [0.1-8808-exec-7] c.z.s.d.v.E.getChangerListByVersionid : ==> Preparing: SELECT * from( SELECT A .requireid, A .starttime, A .devendtime, A .publishtime, b.postname, b.postid, A .requirename, A .baname, A .tlname FROM require_info A, enum_post b WHERE A .postid::INTEGER = b.postid) ri WHERE ri.requireid ::INTEGER= ?

    org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='versionid', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

    Caused by: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

    修改部分主要有两处:

    (1)修改方案:

    <select id="getChangerListByVersionid" parameterType="Integer" resultType="com.zte.saltportal.model.ChangerListBean">

    由于入参是String类型,而parameterType却给了Integer类型》》正确写法parameterType="String".

    【】错误二

    Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

    (2)修改方案:

     SELECT * from( SELECT A .requireid, A .starttime, A .devendtime, A .publishtime, b.postname, b.postid, A .requirename, A .baname, A .tlname FROM require_info A, enum_post b WHERE A .postid::INTEGER = b.postid) ri WHERE ri.requireid ::INTEGER= #{versionid}?

    去掉::INTEGER类型转换》》

    正确写法:将ri.requireid::INTEGER = #{versionid} 改成 ri.requireid = #{versionid}

    (3)考虑versionid入参是否唯一,不唯一将查询出集合,所以Dao中定义返回值:A:对象名称

    操作为:ChangerListBeangetChangerListByVersionid(String versionid);

    改为List<ChangerListBean> getChangerListByVersionid(String versionid);

    同时可以考虑是否需要对入参设置(@Param("versionid")String versionid);

    相关文章

      网友评论

          本文标题:Spring_boot中Mybatis存储过程中出现的错误及修改

          本文链接:https://www.haomeiwen.com/subject/ykmcbqtx.html