1. 程式人生 > >Mybatis中去掉foreach拼接字串中自動新增的前後空格

Mybatis中去掉foreach拼接字串中自動新增的前後空格

例:

<foreach  collection="plantset_types" item="plant" separator="," open="'" close="'">
	${plant.plant_id}
</foreach>

每個${plant.plant_id}獲取的值前後都會自動加空格,‘ 1 , 2 , 3’。

使用下面方法去除空格:

replace(<foreach  collection="plantset_types" item="plant" separator="," open="'" close="'">
	${plant.plant_id}
</foreach>,' ','')

使用SQL語句的replace方法,去掉所有的空格(缺點:去掉所有的空格)。
replace(‘字串’,‘ ’,‘’)。