MyBatis绑定Mapper接口参数到Mapper映射文件sql语句参数

一、设置paramterType

1.类型为基本类型

a.代码示例

映射文件:

<select id="findShopCartInfoById" parameterType="int"
    resultType="ShopCart">
    select*
    from shopcart
    where shopcartid = #{id}
</select>

Mapper接口:

ShopCart findShopCartInfoById(int id);

测试代码:

ShopCartMapper scm = sqlSession.getMapper(ShopCartMapper.class);
ShopCart shopCart = scm.findShopCartInfoById(14);

2.类型为对象类

猜你喜欢

转载自www.cnblogs.com/YeHuan/p/11684590.html
今日推荐