weixin_36649540
CCDS677
采纳率85.7%
2017-06-27 11:51 阅读 2.2k

mybatis update操作报错

3

我单元测试数据的更新操作,一直报错java.sql.SQLException: Parameter index out of range (13 > number of parameters, which is 12)
表结构:
DROP TABLE IF EXISTS business;
CREATE TABLE business(
id int(11) NOT NULL AUTO_INCREMENT COMMENT 主键,
img_file_name varchar(200) DEFAULT NULL COMMENT 图片文件名,
title varchar(50) DEFAULT NULL COMMENT 标题,
subtitle varchar(100) DEFAULT NULL COMMENT副标题,
price decimal(11,2) DEFAULT NULL COMMENT价格(单位:元),
distance int(11) DEFAULT NULL COMMENT距离(单位:米),
number int(11) DEFAULT NULL COMMENT 已售数量,
desc varchar(500) DEFAULT NULL COMMENT 描述,
city varchar(16) DEFAULT NULL COMMENT 城市,
catefory varchar(16) DEFAULT NULL COMMENT 类别,
start_total_num int(11) DEFAULT NULL COMMENT 评论星星总数,
comment_total_num int(11) DEFAULT NULL COMMENT 评论总次数,
PRIMARY KEY (id)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

bean:
private Long id;
private String imgFileName;
private String title;
private String subtitle;
private Double price;
private Integer distance;
private Integer number;
private String desc;
private String city;
private String category;
private Long starTotalNum;
private Long commentTotalNum;

 mybatis的update:

```<update id="update">
        update business b SET b.img_file_name=#{imgFileName},b.title=#{title},b.subtitle=#{subtitle},b.price=#{price}
        ,b.distance=#{distance},b.number=#{number},b.desc=#{desc},b.city=#{city},b.category=#{category},b.star_total_num=#{starTotalNum},b.comment_total_num=#{commentTotalNum}
        where b.id=#{id}
    </update>

单元测试:
@Test
public void update(){
BusinessDto businessDto = new BusinessDto();
Long a = new Long(3);
businessDto.setId(a);
businessDto.setCity("北京");
businessDto.setDesc("啦啦啦啦啦啦");
businessService.modify(businessDto);
}






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

5条回答 默认 最新

  • 已采纳
    loongshawn loongshawn 2017-06-28 02:00
     <update id="update" parameterType="BusinessDto ">
            update business b SET b.img_file_name=#{imgFileName},b.title=#{title},b.subtitle=#{subtitle},b.price=#{price}
            ,b.distance=#{distance},b.number=#{number},b.desc=#{desc},b.city=#{city},b.category=#{category},b.star_total_num=#{starTotalNum},b.comment_total_num=#{commentTotalNum}
            where b.id=#{id}
        </update>
    
    点赞 评论 复制链接分享
  • loongshawn loongshawn 2017-06-28 02:04


    update business b SET b.img_file_name=#{imgFileName},b.title=#{title},b.subtitle=#{subtitle},b.price=#{price}
    ,b.distance=#{distance},b.number=#{number},b.desc=#{desc},b.city=#{city},b.category=#{category},b.star_total_num=#{starTotalNum},b.comment_total_num=#{commentTotalNum}
    where b.id=#{id}

        还有要加if判断
    
    点赞 1 评论 复制链接分享
  • laohuyaochimao 肉末茄子哈 2017-06-27 12:22

    直接用mybatis的工具类生成不就行了,如果这样写要加if判断,name=null在数据库报错

    点赞 评论 复制链接分享
  • qq_31515997 hello.. 2017-06-28 01:22

    mybatis :首先表达下我的观点,我很喜欢用,mybats成的 实体,和映射文件 完全就满足单表操作,不需要去重新写,分页除外

    点赞 评论 复制链接分享
  • Android_app kk1924 2017-07-08 03:18

    其实应该把更多的日志放出来,

    点赞 评论 复制链接分享

相关推荐