1 |
public Posts getPostsById( int id); |
1
2
3
4 |
<!-- 这里的id必须和PostsMapper接口中的接口方法名相同,不然运行的时候也要报错 --> < select id = "getPostsById" resultType = "Posts" parameterType = "int" > select * from posts where id=#{id} </ select > |
1
2
3
4
5
6
7
8
9 |
< 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 |
public void addPosts(Posts posts); |
1
2
3
4 |
<insert id= "addPosts" parameterType= "Posts" > insert into posts(title,context) values ( #{title},#{context}) <!-- 这里sql结尾不能加分号,否则报“ORA-00911”的错误 --> </insert> |
1 |
int updateByExample( @Param ( "user" ) User user, @Param ( "example" ) UserExample example); |
1
2
3
4
5
6
7 |
<update id= "updateByExample" parameterType= "map" > update tb_user set id = #{user.id,jdbcType=INTEGER}, ... < if test= "_parameter != null" > <include refid= "Update_By_Example_Where_Clause" /> </ if > |
1 |
public void batchUpdate(List<Posts> list); |
1
2
3
4
5
6 |
<update id= "batchUpdate" parameterType= "java.util.List" > update posts set badcount= 3 ,goodcount= 5 where id in <foreach collection= "list" item= "item" open= "(" close= ")" index= "index" separator= "," > #{item.id} </foreach> </update> |
1 |
List<User> selectByExample(UserExample example); |
1
2
3 |
<where > <foreach collection= "oredCriteria" item= "criteria" separator= "or" > < if test= "criteria.valid" > |