|
1
2
3
4
5
6
7
8
9
10 |
<!-- 这里的id必须和PostsMapper接口中的接口方法名相同,不然运行的时候也要报错 --> <select id="getPostsById" resultType="Posts" parameterType="int"> select * from posts <if test="_parameter!=0"> where id=#{id} </if> <if test="_parameter==0"> limit 0,1 </if> </select> |
|
1
2
3
4
5
6 |
<typeAliases> <!-- 实体类的别名 --> <typeAlias alias="Posts" type="com.mscncn.batis.model.Posts"/> <typeAlias alias="Pager" type="com.mscncn.batis.model.Pager"/> </typeAliases> |
|
1
2
3
4
5
6
7
8
9 |
<select id="getPostsById" resultType="com.mscncn.batis.model.Posts" parameterType="int"> select * from posts <if test="_parameter!=0"> where id=#{id} </if> <if test="_parameter==0"> limit 0,1 </if> </select> |
|
1
2
3
4
5
6
7
8
9 |
<select id="getPostsById" resultType="com.mscncn.batis.model.Posts" parameterType="int"> select posts_id as "id",post_badCount as "badCount" from posts <if test="_parameter!=0"> where id=#{id} </if> <if test="_parameter==0"> limit 0,1 </if> </select> |
|
1
2
3
4
5 |
<resultMap type="Posts" id="postList"> <id column="posts_id" property="id"/> <result column="posts_title" property="title" /> <result column="posts_context" property="context" /> </resultMap> |
|
1
2
3 |
<select id="getList" resultMap="postList"> select * from posts </select> |