龍巖易富通網(wǎng)絡(luò)科技有限公司

龍巖小程序開發(fā),龍巖分銷系統(tǒng)

where 1=1

2015.09.10 | 17閱讀 | 0條評論 | 未命名

where 1=1 表示永遠(yuǎn)為真,主要是為了便于動態(tài)連接后續(xù)條件。在組合查詢條件時(shí)候多用: String sql="select * from user where 1=1 "; if(username!=null) sql=sql+ " and username='"+username+"'"; if(password!=null) sql=sql+ " and password='"+password+"'"; 這樣方便很多,即使username,password兩者都為空都可以查詢,不用再判斷是否添加WHERE。

贊 (

發(fā)表評論