
Java mysql mybatis批量更新数据库,采用以下写法即可执行,但是数据库连接必须配置:&allowMultiQueries=true
例如:jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&ampcharacterEncoding=UTF-8&allowMultiQueries=true<update id="batchUpdate" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="" close="" separator="">
update test
<set>
test=${item.test}+1
</set>
where id = ${item.id}
</foreach>
</update>
MyBatis是支持普通SQL查询,存储过程和高级映射的优秀持久层框架。MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索。MyBatis使用简单的XML或注解用于配置和原始映射,将接口和Java的POJOs(Plan Old Java Objects,普通的Java对象)映射成数据库中的记录.
java版的实际例子。类同你说的情况private void findChildList(AssetType parent,List<AssetType>list){
String hql = "from AssetType a where a.parentAssetType.assetTypeId=? ORDER BY a.sort,a.assetTypeName asc"
List<AssetType>childList = this.assetTypeDao
.getEntityManager()
.createQuery(hql)
.setParameter(1, parent.getAssetTypeId())
.getResultList()
int size = childList.size()
if(size>0){
for (int i = 0i <sizei++) {
AssetType assetType = childList.get(i)
List<AssetType>childs = assetType.getChildAssetType()
if(childs.size()>0){
list.addAll(childs)
this.findChildList(assetType, list)//递归查询节点的子节点
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)