Mybatis注解配置数据库语句的方法有哪些?
- 内容介绍
- 文章标签
- 相关推荐
本文共计489个文字,预计阅读时间需要2分钟。
t.text + 常用Annotation注解 1.select 语句 @Select(select * from tb_user where tb_id=)
t.text常用Annotation注解
1.select语句
@Select("select * from tb_user where tb_id=#{tb_id}")
通过在Mapper映射接口方法上声明,进行查询,如果需要进行返回结果单独映射,可以通过Results来进行,如下:
@Results({
@Result(id=true,column="tb_id",property="id"),
@Result(column="tb_name",property="name"),
@Result(column="tb_sex",property="sex"),
@Result(column="tb_age",property="age")
})
在results元素中通过{}包含result元素,在result元素中可以通过id属性指定表中的主键,column指的是数据库表的列名
,property表示类中的属性名,当涉及到多个查询参数时,可以通过Param来给方法中的参数进行名称定义,从而对应相应
的查询条件中的#{参数},如下:
List
本文共计489个文字,预计阅读时间需要2分钟。
t.text + 常用Annotation注解 1.select 语句 @Select(select * from tb_user where tb_id=)
t.text常用Annotation注解
1.select语句
@Select("select * from tb_user where tb_id=#{tb_id}")
通过在Mapper映射接口方法上声明,进行查询,如果需要进行返回结果单独映射,可以通过Results来进行,如下:
@Results({
@Result(id=true,column="tb_id",property="id"),
@Result(column="tb_name",property="name"),
@Result(column="tb_sex",property="sex"),
@Result(column="tb_age",property="age")
})
在results元素中通过{}包含result元素,在result元素中可以通过id属性指定表中的主键,column指的是数据库表的列名
,property表示类中的属性名,当涉及到多个查询参数时,可以通过Param来给方法中的参数进行名称定义,从而对应相应
的查询条件中的#{参数},如下:
List

