MyBatis——注解使用
一、注解:
|
注解 |
目标 |
相对应的 XML |
描述 |
|
@Results |
方法 |
<resultMap> |
实现结果集封装 |
|
@Result |
方法 |
<result>/<id> |
可以与@Result 一起使用,封装多个结果集 |
|
@ResultMap |
Method |
N/A |
实现引用@Results 定义的封装 |
|
@Insert @Update @Delete @Select |
方法 |
<insert> <update> <delete> <select> |
新增 更新 删除 查询 |
|
@Param |
Parameter |
N/A |
元素注解 |
二、使用示例:
public interface UserMapper { @Results(id = "resultId", value = { @Result(id=true,column="id",property="id"), @Result(column="name",property="name"), @Result(column="age",property="age") }) @Select("select * from user" ) List<User> selectAll(); @ResultMap("resultId") @Select("select * from user where id = #{id}") User selectByPrimaryKey(@Param("id") Long id); }

浙公网安备 33010602011771号