做项目遇到了个奇怪的问题,项目里面要对商品、账户、进行分别的多条件查询,于是我就采用动态多条件分页查询,起初在做账户部分的时候Mybatis是这样写的
select acc_id,acc_login,acc_name,acc_pass
from account
and acc_id like #{paramsEntity.accId}
and acc_login like #{paramsEntity.accLogin}
and acc_name like #{paramsEntity.accName}
and acc_pass like #{paramsEntity.accPass}
limit #{start},#{rows}
like 后面直接跟#{paramsEntity.accName} 不需要添加单引号
然后完成商品查询的时候我一样写了一套
select goods_Id,goods_name,goods_unit,goods_type,goods_color,goods_store,goods_limit,goods_commission,goods_producer,goods_remark,goods_sel_price,goods_buy_price
from goods
and goods_Id like ${paramsEntity.goodsId}
and goods_name like ${paramsEntity.goodsName}
and goods_unit like ${paramsEntity.goodsUnit}
and goods_type like ${paramsEntity.goodsType}
and goods_color like ${paramsEntity.goodsColor}
and goods_store like ${paramsEntity.goodsStore}
and goods_limit like ${paramsEntity.goodsLimit}
and goods_commission like ${paramsEntity.goodsCommission}
and goods_producer like ${paramsEntity.goodsProducer}
and goods_remark like ${paramsEntity.goodsRemark}
and goods_sel_price like ${paramsEntity.goodsSelPrice}
and goods_buy_price like ${paramsEntity.goodsBuyPrice}
limit #{start},#{rows}
但是运行报错了!!!
错误信息You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%% limit 0,3' at line 3
然后我就给单引号添加上了,然后居然就成了,代码这样子
select goods_Id,goods_name,goods_unit,goods_type,goods_color,goods_store,goods_limit,goods_commission,goods_producer,goods_remark,goods_sel_price,goods_buy_price
from goods
and goods_Id like '${paramsEntity.goodsId}'
and goods_name like '${paramsEntity.goodsName}'
and goods_unit like '${paramsEntity.goodsUnit}'
and goods_type like '${paramsEntity.goodsType}'
and goods_color like '${paramsEntity.goodsColor}'
and goods_store like '${paramsEntity.goodsStore}'
and goods_limit like '${paramsEntity.goodsLimit}'
and goods_commission like '${paramsEntity.goodsCommission}'
and goods_producer like '${paramsEntity.goodsProducer}'
and goods_remark like '${paramsEntity.goodsRemark}'
and goods_sel_price like '${paramsEntity.goodsSelPrice}'
and goods_buy_price like '${paramsEntity.goodsBuyPrice}'
limit #{start},#{rows}
然后我就去查文档,光放文档给出的也是不用加单引号的!!
parameterType=”Blog” resultType=”Blog”>SELECT*FROM BLOG
state=#{state}
AND title like #{title}
AND title like #{author.name}
我的问题还真不知道出在哪里!!!奇了怪了,有空再去搞清楚吧 !!!!