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(‘字符串’,‘ ’,‘’)。

猜你喜欢

转载自blog.csdn.net/king007c/article/details/85276655