mybatis if test 判断字符串的坑

今天调试一个非常简单的test判断字符串查询语句,怎么调试都是不好用,后来百度才发现,是我写的test标签写错了,我写成:

<if test="record.current != null and record.current==‘1‘" >    注意:1旁边是单引号

正确写法:

<if test="record.current != null and record.current==‘1‘.toString()" >

或者:

<if test = ‘record.current != null and record.current==“1”‘> 注意:1 旁边是双引号

因为mybatis会把‘1‘解析为字符,java是强类型语言,所以不能这样写,需要双引号

原文地址:https://www.cnblogs.com/DylanZ/p/10119146.html

时间: 2024-08-30 10:52:35

mybatis if test 判断字符串的坑的相关文章

mybatis xml &lt;if&gt;判断字符串相等

mybatis 映射文件中,if标签判断字符串相等,两种方式: 因为mybatis映射文件,是使用的ognl表达式,所以在判断字符串sex变量是否是字符串Y的时候, <if test="sex=='Y'.toString()"> <if test = 'sex== "Y"'> 注意: 不能使用 <if test="sex=='Y'"> and 1=1 </if> 因为mybatis会把'Y'解析为字

mybatis中if标签判断字符串相等问题

mybatis 映射文件中,if标签判断字符串sfyx变量是否是字符串Y的时候,发现并不管用: <if test="sfyx=='Y' "> and 1=1 </if> 当时就寻思着可能是字符和字符串的问题,改成双引号试试,结果就成功了: <if test = 'sfyx== "Y" '> and 1 = 1 </if> 只能解释为mybatis会把'Y'解析为字符,java是强类型语言,字符串和字符不能直接比较. 原

注意了,Mybatis中条件判断时遇到的坑

1.mapper中比较字符串时需要注意的问题如下: mybatis 映射文件中,if标签判断字符串相等,两种方式:因为mybatis映射文件,是使用的ognl表达式,所以在判断字符串isComplete变量是否是字符串Y的时候<if test="isComplete=='Y'.toString()">或者使用下面的写法<if test = 'isComplete== "Y"'>注意:不能使用以下方式<if test="isCo

判断字符串全为数字

1 判断字符串全为数字 1.1 直接调用 isNumeric 方法 1.1.1 引入commons依赖包 <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.6</version> </dependency>   1.1.2 通过  StringUtils类 调用

判断字符串是不是数字

NumberUtils.isNumber(str)判断字符串是不是数字或者能不能转换成数字 public class StringIsNumber { public static void main(String[] args) { Scanner s = new Scanner(System.in); String str = s.nextLine(); if(NumberUtils.isNumber(str)){ System.out.println("输入的是数字"); }els

练习:判断字符串“mingrikejijavabu”中,字符“i”出现了几次,并将结果输出。

1 // 判断字符串“mingrikejijavabu”中,字符“i”出现了几次,并将结果输出. 2 3 String str="mingrikejijavabu"; 4 5 //方法1:替换法 6 String str1=str.replace("i",""); //将字符串中i替换为空,创建新的字符串 7 System.out.println("i出现的次数为:"+(str.length()-str1.length()))

判断字符串中字母出现的次数用分割法

public class zuoye3 { public static void main(String[] args) { String a="mingrikejijavabu";//判断字符串“i”出现了几次并将其输出 int c=0;//令c为i出现的次数 String[] b=a.split("");//分隔符,把语句分割. for (String x:b)//遍历输出一遍所有字母 { if(x.equals("i"))//是否有与i相等

PHP判断字符串中是否包含指定字符串,支持中文哦

RT,随手写的 1 /** 2 * 判断字符串中是否包含指定字符串 3 * @var source 源字符串 4 * @var target 要判断的是否包含的字符串 5 * @return bool 6 */ 7 function hasstring($source,$target){ 8 preg_match_all("/$target/sim", $source, $strResult, PREG_PATTERN_ORDER); 9 return !empty($strResul

Valid Palindrome ——判断字符串是否为回文串

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41488377 Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama&