- 浏览: 200346 次
- 性别:
- 来自: 重庆
文章分类
最新评论
-
liping0423:
这边文章 的很不错,拿去用了。谢谢
Oracle时间加减 -
Salyang:
黑莓软件还是很多的,而且我有整理,发布在我的站点里了,www. ...
BlackBerry手机常用软件(在8820中测试通过) -
bulktree:
应该有个清单吧
BlackBerry手机常用软件(在8820中测试通过) -
binyan17:
xkorey 写道那些软件都是什么功能?介绍下吧。
里面的软件 ...
BlackBerry手机常用软件(在8820中测试通过) -
xkorey:
那些软件都是什么功能?介绍下吧。
BlackBerry手机常用软件(在8820中测试通过)
1.情况一:多个输入参数循环次数不对称:
处理方式:新建一个JAVABEAN,将各个参数作为其属性进行赋值。在配置文件中,获取其值,进行各自循环。
如下例:要更新的字段Opr的值只有一个,而ID的值却有多个。
public void batchClientAppOperation(String[] appDevIds,String operation) throws Exception { try { AppOperation appOpr=new AppOperation(); appOpr.setOperation(operation); appOpr.setAppDevIds(appDevIds); this.getSqlMapClientTemplate().update("Device.ClientAppOperation", appOpr); } catch (DataAccessException ex) { throw new Exception( Constants.ERROR_CODE_DELETE_USER_BY_ID.getLongValue(), ex); } }
<update id="Device.ClientAppOperation" parameterClass="AppOperation"> update T_Device_App_R_Info set Opr=#operation# where ID in <iterate conjunction="," open="(" close=")" property="appDevIds"> #appDevIds[]# </iterate> </update>2.情况二:多个输入参数循环次数是对称的:
处理方式:新建一个hashmap,将各个参数名作为key,参数值作为value。在配置文件中,获取各key-value,进行各自循环。
如下例:将循环插入/更新的列名作为key,列值作为value放入hashmap中.(列名与列值是一一对应的,即循环次数对等)
<!-- 插入一条新纪录 $与#获取值的方式是一样的,只是$获取是对应参数的值,#会将获取的值加上引号,变为字符串类型。所以,一般用$来获取表名,列名,用#用获取要插入的值。 --> <insert id="customPO_insert" parameterClass="customPO"> INSERT INTO $moduleTable$ (parentID <iterate property="fieldValueList" prepend="," conjunction=","> --fieldValueList是customPO一属性 $fieldValueList[].key$ --循环fieldValueList[]这个数组,因为此数组每个对象是map,可获得map的key. </iterate> ) VALUES (#parentID# <iterate property="fieldValueList" prepend="," conjunction=","> #fieldValueList[].value# </iterate> ) <selectKey resultClass="int" keyProperty="id"> SELECT last_insert_id() </selectKey> </insert> <!--更新--> <update id="customPO_update" parameterClass="customPO"> UPDATE $moduleTable$ SET <iterate property="fieldValueList" conjunction=","> $fieldValueList[].key$ = #fieldValueList[].value# </iterate> WHERE id = #id# </update>(2)
在代码中批量处理:
即是在startBatch()与executeBatch()之间循环调用操作数据库。如下:
public void batchUpdate(final String[] ids,final String appId) throws IEPGMException { try { final HashMap<String, String> map = new HashMap<String, String>(); this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() { public Object doInSqlMapClient( SqlMapExecutor executor) throws SQLException { executor.startBatch(); executor.delete("Application.deleteAppDevTypeMapById", appId); for(int i=0;i<ids.length;i++) { //由于map中key都是appId,ids,所以每次循环赋值后,map中也只有二个key,即是appId,ids,其值会被不断更新. map.put("appId",appId); map.put("ids",ids[i]); executor.insert("Application.insertAppDevTypeMap", map); } executor.executeBatch(); return null; } }); } catch (DataAccessException ex) { throw new IEPGMException( Constants.ERROR_CODE_DELETE_USER_BY_ID.getLongValue(), ex); } }
ibatis配置文件中:
<delete id="Application.deleteAppDevTypeMapById" parameterClass="java.lang.String"> DELETE FROM T_App_Spce_R_Info WHERE App_ID=#appId#; </delete> <insert id="Application.insertAppDevTypeMap" parameterClass="java.util.HashMap"> INSERT INTO T_App_Spce_R_Info(App_ID,Spec_Code) VALUES(#appId#,#ids#); </insert>如何定义多表查询
<typeAlias type="com.coship.dhm.iepgm.admin.entity.Guojia" alias="Guo" /> <resultMap id="GuoResult" class="Guo" > <result column="gid" property="gid" /> <result column="userid" property="userid" /> <result column="gname" property="gname" /> </resultMap> </sqlMap>无须添加如查询之类的东西。
private List<Guojia> guoList;
public List<Guojia> getGuoList() {
return guoList;
}
public void setGuoList(List<Guojia> guoList) {
this.guoList = guoList;
}
<resultMap id="HwjResult" class="Hwj">
<result column="staff_id" property="id" />
<result column="longinName" property="loginName" />
<result column="password" property="password" />
<result column="staff_name" property="username" />
<result column="status" property="status" />
<result column="phone" property="phone" />
<result column="email" property="email" />
<result property="guoList" resultMap="Guo.GuoResult"/>
</resultMap>
<%-- guojia --%>
<td width="20%">
<s:iterator value="#user.guoList" status="index1" id="l">
<%-- <s:property value="#index1.index"/> --%>
<s:property value="gname" />
</s:iterator></td>
<%-- address --%>
<td width="20%">
<s:iterator value="#user.addressList" status="index1" id="l">
<%-- <s:property value="#index1.index"/> --%>
<s:property value="address" />
</s:iterator></td>
<resultMap id="DevTypeResult" class="DevType">
<result column="Spec_Code" property="specCode" />
<result column="Spec_Name" property="specName" />
<result column="Vendor" property="vendor" />
<result column="Brand" property="brand" />
<result column="Model" property="model" />
</resultMap>
<select id="DevType.findNoChoiceDevTypeById" parameterClass="java.lang.String" resultMap="DevTypeResult">
SELECT distinct d.*
FROM T_App_Info a, T_Device_Spec d, T_App_Spce_R_Info r
WHERE a.App_ID=r.App_ID
AND r.Spec_Code!=d.Spec_Code
AND a.App_ID=#appId#
ORDER BY d.Spec_Code;
</select>
发表评论
-
在Tomcat7中JNDI方式使用tomcat-jdbc连接池
2014-12-04 20:16 1491在tomcat中,jndi方式默认使用的是tomca ... -
【转】JAVA23种设计模式
2013-03-01 18:18 1134设计模式主要分三个类型:创建型、结构型和行为型。 其中创建 ... -
用iframe做伪ajax上传文件通用版设计思路
2013-02-28 22:35 0在公司内部不能发布代码到外网,现在此写一下设计思路 ... -
【转】Open Flash Chart支持中文字体旋转最新编译(Version 2 Lug Wyrm Charmer)
2012-09-04 10:51 2174原文地址:http://u.hooto.com/guan ... -
图片延迟加载解决方法
2012-02-13 23:36 4546原文地址:http://blog.tianxiadiyichi ... -
[转]jdbc批量insert———oracle数组类型与forall的应用
2011-12-21 00:35 5062原文:http://blog.itpub.net/post/3 ... -
Tomcat启动优化配置
2012-02-17 20:44 1481# set juli if [ -r "$C ... -
正则表达式元字符说明
2011-12-08 23:13 875元字符 描述 .点 匹配任何单个字符。例如正 ... -
数据库属性hibernate.dialect的设置
2011-12-04 22:40 877为数据库属性hibernate.dialect设置正确的 or ... -
uploadify解决在Chrome中上传HTTP error问题
2011-11-25 10:07 3005今天在做文件上传时,发现uploadify在IE中上传能成功 ... -
【转】玩转三种主流数据库(oracle,sql server,mysql)web翻页
2011-10-30 16:10 1444原文:http://blog.sina.c ... -
在ibatis中调用存储过程
2011-07-28 14:10 10921、配置文件,注意其中的jdbcType,这个不知道可以参考j ... -
JavaScript event KeyCode数字对应键盘大全
2011-06-28 00:08 1156keycode 8 = BackSpace Bac ... -
【转】BigDecimal常用计算方法
2011-06-26 12:57 1059import java.math.BigDecimal; ... -
【转】jQuery选择器总结
2011-06-25 00:04 793jQuery 的选择器可谓之强大无比,这里简单地总结一下 ... -
[转]jQuery操作Table学习总结
2011-06-24 23:22 2159jQuery在客户端操作Table学习:不过有很多很多的不足, ... -
如何在您的网站上增加划词翻译
2010-10-25 15:06 1123任何网站只要将以下代码放入您的网页就可以为您的站点添加划词翻译 ... -
二分查找算法——Java版
2010-04-25 21:39 1341这是将网上的C++版的改写成Java的 理论上把函数f()改 ...
相关推荐
简单易入手,使用mysql数据库进行数据管理
使用ibatis+spring+struts2 做的开发例子 帮助大家一起学习ibatis的整合
velocity+ibatis+mysql+exlipse实例 velocity+ibatis+mysql+exlipse实例 velocity+ibatis+mysql+exlipse实例 velocity+ibatis+mysql+exlipse实例 velocity+ibatis+mysql+exlipse实例
compass+ibatis+spring+struts2整合开发compass+ibatis+spring+struts2整合开发compass+ibatis+spring+struts2整合开发compass+ibatis+spring+struts2整合开发
struts2+spring+ibatis+oracle+分页搜索+上传附件实例!完整版!
maven+springmvc+spring+ibatis+velocity+mysql
ibatis+Spring+struts2整合实例
整合ibatis+spring+struts2 整合ibatis+spring+struts2
springMVC+ibatis+hibernate+spring+boostrap框架
ibatis配置多表关联(一对一、一对多、多对多
oa_权限系统ibatis+spring+struts2 oa_权限系统ibatis+spring+struts2 oa_权限系统ibatis+spring+struts2
MVC模式做的J2EE仓储管理系统,功能包括用户管理、采购管理、销售管理、库存查询、物料管理,使用了struts、ibatis框架、项目包含sql建表语句
ibatis批量处理操作实现,以及sping中需要注意点
完整的ibatis的CRUD+存储过程+动态查询!!!!!!!!
Spring+DWR+ibatis+jQuery+easyUI的框架例子. 完全开放源代码,免费学习与使用。 可以完成基本的后台主界面,报表查询,数据查询,增加,修改等功能。 如果你要做一些报表,后台功能利用这个a框架就可以很方便实现。
struts2+spring+ibatis+mysql AOP日志管理,异常捕获 tomcat6.0+jdk1.6
spring mvc+ibatis+mysql+easyui简单demo
ibatis 批量 增删改查
在idea8上用DWR+ibatis+Ext +mysql 开发的小程序