mybatis xml <if>判断字符串相等

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‘解析为字符,java是强类型语言,所以不能这样写。

原文地址:https://www.cnblogs.com/archermeng/p/9672730.html

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

mybatis xml <if>判断字符串相等的相关文章

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

判断字符串string是数字、json结构、xml结构

import org.json.JSONException; import org.json.JSONObject; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; public class StringTest { /** * @param args */ public static void main(String[] args) { String string1 = "123"; Strin

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.xml中sql编写规范

一.越少的代码,越强悍的功能,xml里面应该6个sql语句就够用了,修改,维护成本很低,见下表 下载 英文名 方法名称 核心点 建议 insert 1.新增数据 如果是自增主键,应该返回主键ID deleteById 2. 根据主键ID删除数据 sql默认加limit 1,防止多删数据 此方法不建议有,建议逻辑删除 updateById 3. 根据主键ID修改数据 sql默认加limit 1,防止多修改数据 selectById 4. 根据主键查询数据 查询一条数据 selectByIdForU

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

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

判断字符串是不是数字

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