直接在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>