Mybatis dynamic sql considerations

A. For string variables, you need to judge the null value and the empty string, and to remove the blanks at both ends,
other types only need to judge null
B. For the basic types of variables, if the entity is received in this way, the foreground is If it is an empty string, an exception will be reported,
so it is best to use the wrapper class of the entity class instance variable as the basic type replacement type
C. For elements in web page tags, if the value attribute is not written, the default value is Content
D. If there are multiple parameters, you can use

//错误使用
<if test="ename != null && ''.equals(ename.trim())"></if>
//正确使用
<!-- 判断ename不为空,并且不为空字符串,trim()去掉前后空格 -->
<if test="ename != null and ''.equals(ename.trim())">

//原因在动态sql时xml文件识别不了&&,所以使用and,表示并且
Published 23 original articles · Like1 · Visits 169

Guess you like

Origin blog.csdn.net/weixin_45528650/article/details/105483045