。。老师看一下吧。。。。。

来源:5-1 MyBatis数据插入操作

dobe001

2020-02-24 16:03:09

<insert id=" insert" parameterType="com.imooc.mybatis.entity.Goods">
    INSERT INTO t_goods(title,sub_title,original_cost,current_price,discount,is_free_delivery,category_id)
    VALUE (#{title},#{subTitle},#{originalCost},#{currentPrice},#{discount},#{isFreeDelivery},#{categoryId})
    <selectKey resultType="Integer" keyProperty="goodsId" order="AFTER">
        select last_insert_id()
    </selectKey>
</insert>
 @Test
    public void testInsert() throws Exception{
        SqlSession session = null;
        try {
            session = MyBatisUtils.openSession();
            Goods goods = new Goods();
            goods.setTitle("测试商品");
            goods.setSubTitle("测试子标题");
            goods.setOriginalCost(200f);
            goods.setCurrentPrice(100f);
            goods.setDiscount(0.5f);
            goods.setIsFreeDelivery(1);
            goods.setCategoryId(43);
            //insert()方法返回值代表本次成功插入的记录总数
            int num = session.insert("goods.insert", goods);
            session.commit();
            System.out.println(goods.getGoodsId());
        } catch (Exception e) {
            if (session != null) {
                session.rollback();
            }
            throw e;
        }finally {
            MyBatisUtils.closeSession(session);
        }
    }
}

http://img.mukewang.com/climg/5e538329091e3f6203360195.jpg


写回答

2回答

好帮手慕柯南

2020-02-24

同学老师在你的另一个问答下回复你了

https://class.imooc.com/course/qadetail/195975

祝学习愉快~

0

dobe001

提问者

2020-02-24

values的s加上了。还是一样的错。

0

0 学习 · 8016 问题

查看课程