<select id="selectAll" resultMap="tblTicketCardDistributionMap"> select * from TBL_TICKET_CARD_DISTRIBUTION <where> <choose> <when test="query.orderType != null and query.orderType != '' and query.orderType =='03'"> and ORDER_TYPE = #{query.orderType} and ( <if test="query.inStationId != null and query.inStationId != '' "> IN_STATION_ID = #{query.inStationId} </if> <if test="query.outStationId != null and query.outStationId != '' "> or OUT_STATION_ID = #{query.outStationId} </if> ) </when> <otherwise> <if test="query.orderType != null and query.orderType != '' "> and ORDER_TYPE = #{query.orderType} </if> <if test="query.inStationId != null and query.inStationId != '' "> and IN_STATION_ID = #{query.inStationId} </if> <if test="query.outStationId != null and query.outStationId != '' "> or OUT_STATION_ID = #{query.outStationId} </if> </otherwise> </choose> <if test="query.lineId != null and query.lineId != '' "> and LINE_ID = #{query.lineId} </if> <if test="query.stationId != null and query.stationId != '' "> and STATION_ID = #{query.stationId} </if> <if test="query.operatorId != null and query.operatorId != '' "> and OPERATOR_ID = #{query.operatorId} </if> <if test="query.curDay != null and query.curDay != '' "> and CUR_DAY = #{query.curDay} </if> <if test="query.beginTime != null and query.beginTime != '' "> and OPERATE_TIME between #{query.beginTime} and #{query.endTime} </if> </where> </select>报错语法有问题,修改正确的
时间: 2024-03-18 12:42:12 浏览: 16
根据报错信息,需要看一下具体是哪个语法有问题。不过根据代码,有一个语法问题:
在`<when>`标签中,使用了`<if>`标签,应该改为`${}`,例如:
```
<when test="query.orderType != null and query.orderType != '' and query.orderType =='03'">
and ORDER_TYPE = #{query.orderType} and (
${query.inStationId != null and query.inStationId != '' ? 'IN_STATION_ID = #{query.inStationId}' : ''}
${query.outStationId != null and query.outStationId != '' ? ' or OUT_STATION_ID = #{query.outStationId}' : ''}
)
</when>
```
这样应该就能解决语法问题了。
相关问题
<select id="getQueryBook" parameterType="String" resultMap="bookResult"> select * from book where book_name = #{bookName} </select>改为模糊查询
可以将SQL语句修改为:
```
<select id="getQueryBook" parameterType="String" resultMap="bookResult">
select * from book where book_name like CONCAT('%',#{bookName},'%')
</select>
```
这样就可以进行模糊查询,匹配包含关键字的书籍名称。
<select id="selectdate" resultMap="resultemp"> select * from emp <where> create_time > #{createTime} OR entrydate NOT NULL </where> </select> 这条动态sql语法有什么问题
这条动态 SQL 语句存在两个问题:
1. 第一个问题是在 `<where>` 标签中的条件语句 `create_time > #{createTime}` 的后面使用了 `OR` 关键字,但是缺少了具体的条件表达式。你需要提供一个条件表达式来完成这个逻辑运算,例如 `OR entrydate IS NOT NULL` 表示 entrydate 不为空。
2. 第二个问题是 `entrydate NOT NULL` 这个表达式是错误的。在 SQL 中,我们使用 `IS NOT NULL` 来判断字段是否不为空。所以正确的写法是 `entrydate IS NOT NULL`。
修正后的 SQL 语句应该是:
```sql
<select id="selectdate" resultMap="resultemp">
select * from emp
<where>
create_time > #{createTime}
OR entrydate IS NOT NULL
</where>
</select>
```
请注意,这仅仅是修正了语法错误,是否符合你的业务逻辑还需要你自己确认。