项目中可能会涉及到,多条记录的增加。我们一般会多个form使用js提交的方式,或者多个form多次提交的方式。这里谈一点自己在项目中应用到的实例解决方案。涉及到struts+ibatis,freemarker表示页面。
操作对象Model:Test.java
class Test{
String name;
String nameUrl;
set...()
get...()
}
form表单。如:test.ftl
<form name="addInfo" action="test.action" method="post" onsubmit="return checkForm();">
<table width="99%" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td width="100%" colspan="2">添加</td>
</tr>
<tr>
<td width="15%" height="24" align="right">标题1:</td>
<td width="85%">
<input type="text" name="listTest[0].name" id="name0" value="" size="60" maxlength="40" />
</td>
</tr>
<tr>
<td width="15%" height="24" align="right">链接1:</td>
<td width="85%">
<input type="text" name="listTest[0].nameUrl" id="nameUrl0" value=" />
</td>
</tr>
<tr>
<td width="15%" height="24" align="right">标题2:</td>
<td width="85%">
<input type="text" name="listTest[1].name" id="name1" value="" size="60" maxlength="40" />
</td>
</tr>
<tr>
<td width="15%" height="24" align="right">链接2:</td>
<td width="85%">
<input type="text" name="listTest[1].nameUrl" id="nameUrl1" value=" />
</td>
</tr>
<tr>
<td width="15%" height="24"> </td>
<td width="85%"><input type="submit" value="保存" id="saveImg" /> <input type="reset" value="取消" name="" /></td>
</tr>
</table>
</form>
struts的Action:TestAction.java
class TestAction extends ActionSupport{
List<Test> listTest;
public String test() throws Exception{
//调用service保存(Dao的insertListTest方法)
}
setListTest...
getListTest...
}
Struts的配置:struts.xml
<action name="test" class="包路径.TestAction" method="test">
<result name="success" type="freemarker">/success.ftl</result>
<result name="error" type="freemarker">/error.ftl</result>
</action>
ibatis的sqlmap配置:sqlmap-config.xml,这里假设有表test(name,nameUrl)
<update id="insertListTest" parameterClass="java.util.List">
INSERT INTO test(name,nameUrl)
VALUES
<iterate conjunction=",">
(#value[].name#,#value[].nameUrl#)
</iterate>
</update>
注意,这里的插入没有使用ibatis的insert而是update操作,是因为批量更新的时候insert无法返回影响的条数,所以使用了update方法。这里大家有更好的方法欢迎共享
分享到:
相关推荐
里面有spring+struts2+ibatis整合的jar包,
struts2+spring+Ibatis框架包
struts2+spring+ibatis+mysql AOP日志管理,异常捕获 tomcat6.0+jdk1.6
spring3+struts2+ibatis工程demo;
Struts2+IBatis整合
struts2+ibatis+mysql 项目 个人开发小网站,压缩包里面的sql为数据库。。。
struts2+spring+ibatis+oracle+分页搜索+上传附件实例!完整版!
Spring+Struts2+iBatis简要说明
是将struts2+spring3+iBATIS进行整合。
有关Struts2+Spring+Hibernate和Struts2+Spring+Ibatis的整合实例demo 原创,完全基于eclipse开发
struts2+ibatis的小例子,但没有集成 spring,你下载下来可以自己尝试集成
spring2+struts1+ibatis2spring2+struts1+ibatis2spring2+struts1+ibatis2spring2+struts1+ibatis2spring2+struts1+ibatis2spring2+struts1+ibatis2spring2+struts1+ibatis2
北京出差项目 struts2+ibatis
struts2 + spring + ibatis 实例 struts2 + spring + ibatis 实例 struts2 + spring + ibatis 实例 struts2 + spring + ibatis 实例 struts2 + spring + ibatis 实例
Spring+Struts2+Ibatis整合例子,jar太大不让上传,删除了,看配置文件吧
自学两天ibatis后自己做的struts2+spring+ibatis+jquery ajax的登录注册
struts2+spring+ibatis的小demo
基于spring+struts2+ibatis开发的简单项目,里面有增加,修改,删除,查找功能,前台使用了ligerUI插件,需在jsp页面引用ligerUI的js文件,适合有一定jquery,java的初学者,并对ligerUI有一定的了解,否则将很难理解...
struts2+spring+ibatis项目实例
一个简单的spring+struts+ibatis整合的实例,实现了用户登录,用户登录成功则显示欢迎信息,失败则显示用户名或密码错误,该实例非常简单基础,特别适合新人学习,工程包含了必要的资源包,部署到服务器中及可运行,...