mybatis将表名或字段名当做参数传入问题

mybatis 如果直接用#{}传入表名或者字段名,会默认加上双引号,所以此时用${}传入即可

1
2
3
4
5
6
7
8
9
10
<select id="selectByParam" resultType="com.hyyt.webservice.modules.product.dto.ShopProductInfoDTO">
SELECT spi.*,sb.brandName FROM shop_product_info spi LEFT JOIN shop_brand sb on spi.brandId = sb.brandId
<where>
<if test="productName != null">spi.productName LIKE CONCAT('%',#{productName},'%')</if>
<if test="productId != null">and spi.productId=#{productId}</if>
<if test="brandName != null">and sb.brandName LIKE CONCAT('%',#{brandName},'%')</if>
</where>
<if test="sortType != null">order by ${sortType}</if>
<if test="sortOrder != null">${sortOrder}</if>
</select>
赏个🍗吧
0%