1.基础传参
java
/***
* mysql获取所有表以及备注信息
*
* @param database
* @return
*/
@Select("SELECT\n" +
"table_name name,TABLE_COMMENT VALUE \n" +
"FROM INFORMATION_SCHEMA.TABLES a \n" +
"WHERE a.table_schema= #{database} \n" +
"AND table_type='BASE TABLE'")
List<Map<String, Object>> getMySqlTableList(@Param("database") String database);
2.动态传参
java
@Update({"<script>",
"update Author",
" <set>",
" <if test='username != null'>username=#{username},</if>",
" <if test='password != null'>password=#{password},</if>",
" <if test='email != null'>email=#{email},</if>",
" <if test='bio != null'>bio=#{bio}</if>",
" </set>",
"where id=#{id}",
"</script>"})
void updateAuthorValues(Author author);
3.// 返回非自增主键
java
@Insert({"INSERT INTO sys_user(user_name,user_password,user_email,user_info) values(#{userName},#{userPassword},#{userEmail},#{userInfo})"})
@Options(useGeneratedKeys = true, keyProperty = "id")
int insert2(SysUser user);
4.//resultMap方式进行对象映射配置(Mybatis3.3.0版本以前)
java
@Results({
@Result(property="id",column="id",id=true),
@Result(property="roleName",column="role_name"),
@Result(property="createTime",column="create_time"),
@Result(property="enabled",column="enabled"),
@Result(property="createBy",column="create_by"),
})
@Select("select id,role_name,enabled,create_by,create_time"
+ "from role where id=#{id}")
Role selectById2(long id);
5.Provider注解
java
public String selectById(final long id){
return new SQL().SELECT("id,role_name,enabled,create_by,create_tim").FROM("role").WHERE("id=#{id}").toString();
}
6.根据id查询
@SelectProvider(type=RoleProvider.class,method="selectById")