bboss 动态sql使用foreach循环示例
本文介绍bboss 动态sql使用foreach循环示例。切入正题。
在sql配置文件中配置的sql语句有时需要用到foreach循环控制语句以及循环计数器velocityCount,以便遍历外部传入的list数据。在这里我们简单地介绍这个功能。
首先看看sql配置文件中配置的sql语句:
<property name="updateLkYjZt"> <![CDATA[ update dtjf.t_zt_zdry_cklkyjqbxx y set y.sjqszt = '5' where y.yjlx='2' and y.ldxxbh in ( #foreach($ldxxbh in $ldxxbhs) #if($velocityCount == 1) '$ldxxbh' #else ,'$ldxxbh' #end #end ); ]]></property>
#foreach($ldxxbh in $ldxxbhs) #if($velocityCount == 1) '$ldxxbh' #else ,'$ldxxbh' #end #end
public void updateLkYjZt(List<String> ldxxbhs) {try {Map datas = new HashMap();datas.put("ldxxbhs",ldxxbhs);executor.updateBean("updateLkYjZt", datas);} catch (SQLException e) {e.printStackTrace();}}