mybatis中當查詢條件有Boolean類型的時候,為false時查詢無效
eg:
<if test="isOk != null and isOk !=''">
and is_ok = #{isOk}
</if>
此時當isOk為false時,並未查詢出is_ok對應的結果來
找原因:
直接到數據庫使用腳本查詢
select * from table where is_ok = false
此時能查出is_ok為0的數據
select * from table where is_ok = true
此時能查出is_ok為1的數據
此時定位問題是否在
此時能查出is_ok為0的數據
<if test="isOk != null and isOk !=''">
通過排查去掉and isOk!=’’,可以正確的查出
所以正確的查詢結構是:
<if test="isOk != null">
and is_ok = #{isOk}
</if>
經研究:
mybatis的if判斷里面最好不要使用boolean值:
mybatis會默認把空值轉為false。所以如果遇見前面傳空值,這個字段在mybatis里面永遠就是false了,可以使用數字類型代替,但是不要使用0作為參數。
druid數據庫解密加密
import com.alibaba.druid.filter.config.ConfigTools;
語句:
@Test
public void test2() throws Exception{
//解密
String word="NaSb06jVxVBGcmMeuv3wiRH6oiMLFVA0bRs6stSSz2m52pLJLne2uYQNZgIHJHfKn+TaPPw/lqVCpv2ylCaE9w==";
String decryptword = ConfigTools.decrypt(word);
System.out.println("++++++");
System.out.println(decryptword);
}
@Test
public void testEncrypt() throws Exception
{
//加密
String password ="xxxxxxx";
String encryptword = ConfigTools.encrypt(password);
System.out.println(encryptword);
}
點點滴滴積累!