Mybatis自定义sql,进行insert、update、delete操作,如何返回影响的行记录数???

直接在mapper接口文件直接返回 int 类型即可,sql语句和正常一样,无需设置返回值类型,mybatis框架会自动完整这些功能

接口:UserMapper.java

public interface UserMapper {
    int insert(User record);
}

Mapper映射文件:UserMapper.xml

<insert id="insert" parameterType="com.itheima.springmvc.pojo.User" >  <!-- 无需设置返回值类型parameterType -->
    insert into user (id, username, birthday, 
      sex, address)
    values (#{id,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{birthday,jdbcType=DATE}, 
      #{sex,jdbcType=CHAR}, #{address,jdbcType=VARCHAR})
</insert>

猜你喜欢

转载自blog.csdn.net/li_tiantian/article/details/81776765
今日推荐