Mybatis的 mapper.xml 中 update 語句使用 if 標簽判斷對像屬性是否為空值。
UserDTO是傳過來參數的類型,userDTO是在mapperDao接口中給更新方法的參數起的別名。
mapperDao.java
1
|
int updata( @Param ( "userDTO" ) UserDTO userDTO); |
mapper.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<update id= "updata" parameterType= "UserDTO" > UPDATE table u <set> < if test= " userDTO.age!=null and userDTO.age !='' " > u.identity = #{userDTO.age}, </ if > < if test= " userDTO.name !=null and userDTO.name !='' " > u.name = #{userDTO.name}, </ if > </set> <where> u.id = #{userDTO.id} </where> </update> |
總結
以上所述是小編給大家介紹的Mybatis和orcale update語句中接收參數為對象的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
原文鏈接:http://www.cnblogs.com/gczmn/archive/2017/09/05/7481696.html