通过一组学生的id,批量设置他们的isleave为1。
使用iterate的两种方案
1.使用IN关键字
<update id="setStudentLeac.update1" parameterClass="java.util.List"> update tb_student set isleave=1 where student_id in (<iterate conjunction=",">#[]#</iterate>) </update>
2.循环update执行
<update id="setStudentLeac.update" parameterClass="java.util.List"> <iterate conjunction=""> update tb_student set isleave=1 where student_id =#[]#; </iterate> </update>
第2种方案一直会报错。 但是提示的sql根本看不出哪里错了 作为悬案吧。暂时用1方法
例子:
主配置文件 struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <constant name="struts.ui.theme" value="simple" /> <constant name="struts.multipart.maxSize" value="10485760" /> <!-- 文件上传为10M --> <package name="main" extends="struts-default" > <interceptors> <interceptor name="refuseGet" class="com.growup.tool.NoGetInterceptor"> </interceptor> </interceptors> <global-results> <result name="index">/html/index.jsp</result> <result name="Exception" type="redirect">/ExceptionAction.action</result> <result name="exception" >/html/Exception.jsp</result> </global-results> <global-exception-mappings> <exception-mapping result="Exception" exception="java.lang.Exception"/> </global-exception-mappings> <!--登录请求done --> <action name="actionLogin" class="com.growup.action.LoginAction" method="checkLogin"> <result name="success" type="redirect">/html/teacherLogin.jsp</result> <result name="error">/html/index.jsp</result> </action> </package> <!-- Add packages here --> <constant name="struts.ui.theme" value="simple" /> <constant name="struts.ui.templateDir" value="template" /> <constant name="struts.ui.templateSuffix" value="ftl" /> <include file="struts-manage.xml"></include> </struts>
从配置文件 struts-manage.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <include file="struts.xml"></include> <package name="manage" extends="main" > <!-- 只给添加学生 done --> <action name="addstudentAction" class="com.growup.action.SetBasicInfoAction" method="onlySetStudents"> <interceptor-ref name="refuseGet"></interceptor-ref> <interceptor-ref name="defaultStack"/> </action> </package> </struts>
可以看到struts-manage.xml中可以使用refuseGet这个拦截器。只是include是不行的。本来以为这样会有冲突。继承的action和主文件中的action冲突。不过没有发生。