weixin_42218038
随缘56
采纳率18.2%
2019-05-14 20:56 阅读 2.3k

mybatis的参数一直出错,该怎么解决

10
<delete id="deleteCar" parameterType="com.myMall.model.Car">
        DELETE FROM car WHERE car_id=#{car_id};
    </delete>
Error updating database.  Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='car_id', 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 non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
### The error may exist in sqlmap/Car.xml
### The error may involve car.deleteCar-Inline
### The error occurred while setting parameters
### SQL: DELETE FROM car WHERE car_id='?';
### Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='car_id', 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 non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).] with root cause
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).

该怎么解决

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

8条回答 默认 最新

  • hjs218 Json-Huang 2019-05-14 21:36

    参数类型不对,把

    parameterType="com.myMall.model.Car"
    

    改成

    parameterType="java.lang.String"
    
    点赞 评论 复制链接分享
  • qq_19309473 Roc-xb 2019-05-14 22:38

    把sql语句中的分号去掉吧,在mybatis中写分号会导致执行过程报错,望采纳!

    点赞 评论 复制链接分享
  • weixin_42452027 创业斑马线 2019-05-15 01:53

    这很明显是指类型错误,把parameterType="com.myMall.model.Car"这个去掉就可以了。传参进来时只传car_id。

    点赞 评论 复制链接分享
  • Arthur_ZBY Arthur_ZBY 2019-05-15 08:40

    把parameterType="com.myMall.model.Car"和sql的分号去掉,在接口方法参数前加一个@Param("car")注解,然后SQL里把car_id=#{car_id}改成car_id=#{car.car_id}试一下行不行

    点赞 评论 复制链接分享
  • u013254183 老铁咖啡 2019-05-15 09:03
    //Dao
    public int deleteCar(Car car);
    
    //Mapper
    <delete id="deleteCar" parameterType="com.myMall.model.Car">
        DELETE FROM car WHERE car_id=#{car_id,jdbcType=VARCHAR}
    </delete>
    
    点赞 评论 复制链接分享
  • qq_39647714 qq_39647714 2019-05-15 09:11

    找不到car_id,是不是你Car的类中不是这么命名的?

    点赞 评论 复制链接分享
  • wangml010 wangml010 2019-05-15 09:40

    参数类型错误,你穿进来的是string类型的参数,但是你的parameterType 却写一个 Car 类型,当然报错了,parameterType 应该是 string

    点赞 评论 复制链接分享
  • Amo_lt Amo_lt 2019-05-15 09:58

    com.myMall.model.Car中的car_id是car_id还是carId。

    以及,你的dao层是怎么传值的?是deleteCar(Car car)还是deleteCar(String car_id)

    点赞 评论 复制链接分享

相关推荐