<if test="param.cityName != null and ( param.cityName neq'全国' or param.cityName neq '全市')"> and city_name =#{param.cityName} </if>是否正确
时间: 2024-03-16 14:44:11 浏览: 23
这段代码的语法是错误的。如果要实现两个条件的 OR 判断,在语法上需要使用 `or` 关键字来连接两个条件,而不是使用逻辑非操作符 `neq`。
正确的语法应该是:
```xml
<if test="param.cityName != null and (param.cityName != '全国' or param.cityName != '全市')">
and city_name = #{param.cityName}
</if>
```
在这个例子中,使用了逻辑运算符 `and` 将两个条件连接起来,表示这两个条件都必须成立。其中,第二个条件使用了逻辑运算符 `or` 将两个条件连接起来,表示只要其中一个条件成立,整个条件表达式就为真。
需要注意的是,`test` 属性中的条件表达式需要使用 OGNL 表达式语言来编写。在这个例子中,假设 `param.cityName` 是一个字符串类型的变量,那么可以使用以下语法:
```xml
<if test="param.cityName != null and (param.cityName != '全国' or param.cityName != '全市')">
and city_name = #{param.cityName}
</if>
```
如果 `param.cityName` 不是 null,且它的值不是 `'全国'` 或 `'全市'`,整个条件表达式就为真,将会执行 `<if>` 标签中的 SQL 语句。否则,将会忽略这个标签,不执行任何 SQL 语句。
相关问题
<if test="param.cityName != null and (param.cityName !='全国' or param.cityName != '全市')"> and city_name =#{param.cityName} </if>为什么param.cityName为全国还会执行
根据你提供的代码,<if test="param.cityName != null and (param.cityName !='全国' or param.cityName != '全市')"> and city_name =#{param.cityName} </if>这段代码的意思是:如果param.cityName不为null且param.cityName不等于'全国'或者param.cityName不等于'全市',则执行and city_name =#{param.cityName}。因此,当param.cityName为'全国'时,第一个判断条件为true,第二个判断条件为false,整个判断条件为true,所以会执行and city_name =#{param.cityName}。如果你想要当param.cityName为'全国'时不执行and city_name =#{param.cityName},可以将判断条件修改为<if test="param.cityName != null and param.cityName !='全国' and param.cityName != '全市'"> and city_name =#{param.cityName} </if>。
<update id="updateByParamSelective"> <!-- WARNING - @mbg.generated This element is automatically generated by MyBatis Generator, do not modify. --> update t_galaxy_cal_slots_used <set> <if test="record.id != null"> id = #{record.id,jdbcType=BIGINT}, </if> <if test="record.gmtCreate != null"> gmt_create = #{record.gmtCreate,jdbcType=TIMESTAMP}, </if> <if test="record.gmtModified != null"> gmt_modified = #{record.gmtModified,jdbcType=TIMESTAMP}, </if> <if test="record.appCode != null"> app_code = #{record.appCode,jdbcType=VARCHAR}, </if> <if test="record.executeType != null"> execute_type = #{record.executeType,jdbcType=VARCHAR}, </if> <if test="record.useedSlots != null"> useed_slots = #{record.useedSlots,jdbcType=INTEGER}, </if> <if test="record.calInstanceId != null"> cal_instance_id = #{record.calInstanceId,jdbcType=VARCHAR}, </if> </set> <if test="_parameter != null"> <include refid="Update_By_Param_Where_Clause" /> </if> </update>解释以上代码
以上代码是一个MyBatis Generator生成的更新语句。它用于更新表t_galaxy_cal_slots_used中的记录。具体解释如下:
- `<update id="updateByParamSelective">`:定义了一个更新语句的id。
- `<set>`:设置更新的字段和值。
- `<if>`:用于判断字段是否需要更新。
- `record.id`、`record.gmtCreate`、`record.gmtModified`、`record.appCode`、`record.executeType`、`record.useedSlots`、`record.calInstanceId`:这些都是实体类中的属性,通过`#{}`语法获取属性值。
- `jdbcType=BIGINT`、`jdbcType=TIMESTAMP`、`jdbcType=VARCHAR`、`jdbcType=INTEGER`:指定了属性的JDBC类型。
- `<include refid="Update_By_Param_Where_Clause" />`:引用了一个名为"Update_By_Param_Where_Clause"的SQL片段,用于生成更新语句的WHERE条件。
总结起来,以上代码是根据传入的参数动态生成更新语句,只更新非空字段,并可以根据条件生成WHERE子句。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
给下面代码增加分页功能,要求细致,逻辑清楚,<form action="./../selectNews" method="post"> <input type="text" name="key" id="key" placeholder="请输入标题"/> <input type="submit" value="查询"/> 发布新闻 返回主页 </form> 新闻编号 新闻标题 <%-- 新闻内容 --%> 新闻类别 发布人 发布时间 状态 是否头条 操作 <c:forEach items="${newslist}" var="u"> ${u.nid} ${u.title} <%-- ${u.content} --%> ${u.type} ${u.userName} ${u.pubTime} <c:choose> <c:when test="${u.state==0}">未审核</c:when> <c:when test="${u.state==1}">审核通过</c:when> <c:otherwise>未通过</c:otherwise> </c:choose> <c:choose> <c:when test="${u.top==0}">否</c:when> <c:otherwise>是</c:otherwise> </c:choose> <c:choose> <c:when test="${user.rule==1}"> 查看 修改 删除 审核 </c:when> <c:when test="${user.rule==0 && user.uid==u.uid}"> 查看 修改 删除 </c:when> <c:otherwise> 查看 </c:otherwise> </c:choose> </c:forEach>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)