使用注解开发
- 核心配置文件
<mappers>
<mapper class="com.skl.dao.UserMapper"/>
</mappers>
- 注解在接口上实现
@Select("select * from user")
List<User> getUsers();
本质:反射机制实现
增
public interface UserMapper {
@Insert("insert into user(name,age,`like`)values(#{name},#{age},#{like} )")
Integer addUserInfo(User user);
}
删
public interface UserMapper {
@Delete("delete from user where id = #{id}")
Integer deleteUserInfo(int id);
}
改
public interface UserMapper {
@Update("update user set name = #{name},age = #{age},`like` = #{like} where id = #{id}")
Integer updateUserInfo(User user);
}
查
public interface UserMapper {
@Select("select * from user where id = #{id}")
List<User> getUserInfo(@Param("id") Integer id);
}