1、in 语句
1)sql语句:
select * from user where id in ('1','2','3');
2)Mybitis
select * from user where id in
<foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
#{id}
</foreach>
2、截取字符串,拼接字符串,模糊查询
SELECT
u.*
FROM
user_info u
LEFT JOIN supervise_role_user ru ON u.id = ru.user_id
LEFT JOIN supervise_role r ON ru.role_id = r.id
WHERE
u.flag = 1
AND ru.client_id = ?1
AND u.belong_area LIKE CONCAT( SUBSTR(?3, 1, 6 ), '%' )
AND ru.del_flag = 1
AND r.del_flag = 1
AND r.role_name = ?2
注: 上面的sql为hibernate框架下写的sql语句
①用到的注解:@Query(value = “sql语句”,, nativeQuery = true)
②?1、?2、?3是占位符,分别代表第一个、第二个、第三个参数;
③ SUBSTR(? 3, 1, 6 ):截取第三个入参,前6位字符;
④CONCAT(a,b):拼接字符串;