Mybatis dynamic query
2012-11-28 01:43
295 查看
In my project, I ran into the issue that I have to use Sql In statement and the value in the in() is dynamic. With mybatis, we can create dynamic sql foreach.
Here is my case:
1. In the mapper class, I define my method:
2. In the mapper.xml file, I define my sql statement.
That's all. It's very easy, right?
For more dynamic queries, read the link:
http://loianegroner.com/2011/03/ibatis-mybatis-working-with-dynamic-queries-sql/
Here is my case:
1. In the mapper class, I define my method:
@Component("twitterTweetMapper") public interface TweetMapper{ public List<Tweet> getTweetsByOrganizationIds(List<Long> organizationIds); }
2. In the mapper.xml file, I define my sql statement.
<select id="getTweetsByOrganizationIds" resultType="org.twitter.model.Tweet"> SELECT * FROM TWEET WHERE ORGANIZATIONID in <foreach item="item" index="index" collection="list" open="(" separator="," close=")"> #{item} </foreach> ORDER BY TWEETCREATEDATE DESC LIMIT 3 </select>
That's all. It's very easy, right?
For more dynamic queries, read the link:
http://loianegroner.com/2011/03/ibatis-mybatis-working-with-dynamic-queries-sql/
相关文章推荐
- Mybatis Dynamic Query 框架整合
- Mybatis Dynamic Query 前言
- Mybatis Dynamic Query 2.0.2
- Mybatis Dynamic Query 框架整合
- Mybatis Dynamic Query 2.0 入门
- Mybatis Dynamic Query 1.0.2版本
- Mybatis Dynamic Query 2.0 入门
- DynamicQueryable基于Linq的动态查询
- Mybatis框架不同命名空间相同查询id出现queryById is ambiguous in Mapped Statements collection
- Can I use MyBatis to generate Dynamic SQL without executing it?
- mybatis(ibatis)中的动态sql<dynamic prepend="where"><isNotEmpty>的讲解
- Mybatis Query was empty错误
- Dynamic Query Adapter Epicor E10
- Dynamic Query System 基本SBT
- dynamic query on sql
- Liferay Dynamic Query API
- mybatis报错:A query was run and no Result Maps were found for the Mapped Statement
- asp.net MVC EF dynamic query
- spring.data.jpa.query :Cannot use native queries with dynamic sorting and/or pagination in method
- LINQ Dynamic Query Library