MYBATIS+MYSQL 批量操作数据库
2017-10-25 10:38
411 查看
批量操作数据库可减少数据库连接次数,大大提高运行速率。
一、批量插入:
Mapper.xml
Mapper.java
二、批量筛选
Mapper.xml
Mapper.java
三、多参数批量筛选
Mapper.xml
Mapper.java
Service略
在Controller中组装Map
四、批量更新
Mapper.xml
Mapper.java
一、批量插入:
Mapper.xml
<insert id="insertList" useGeneratedKeys="true" parameterType="java.util.List" > insert into tableA (parent_category, category, cate_type, parent_cate_id, cate_id) values <foreach collection="list" item="item" index="index" separator=","> (#{item.parentCategory},#{item.category},#{item.cateType}, #{item.parentCateId},#{item.cateId}) </foreach> </insert>
Mapper.java
int insertList(List<EntryA> list);
二、批量筛选
Mapper.xml
<select id="selectByPrimaryKeyList" resultMap="BaseResultMap" > select <include refid="Base_Column_List" /> from case_description where id in( <foreach item="item" index="index" collection="list" separator=","> #{item} </foreach>) </select>
Mapper.java
List<BaseResultMap> selectByPrimaryKeyList(List<Integer> list);
三、多参数批量筛选
Mapper.xml
<select id="selectByMap" parameterType="java.util.Map" resultType="java.lang.Integer"> SELECT desc_id from tableA where subtask_id=#{subTaskId,jdbcType=INTEGER} and desc_id in( <foreach collection="list" item="item" index="index" separator=","> #{item} </foreach> ) </select>
Mapper.java
List<Integer> selectByMap(Map<String, Object> map);
Service略
在Controller中组装Map
Map<String, Object> paramMap = new LinkedHashMap<String, Object>(); paramMap.put("subTaskId", subtaskid); paramMap.put("list", idList);
四、批量更新
Mapper.xml
<update id="updateByList" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" open="" close="" separator=";"> update tableA <set> cate_id=#{item.cateId} </set> where app_id = #{item.appId} </foreach> </update>
Mapper.java
Integer updateByList(List<EntryA> list);
相关文章推荐
- mybatis 对oracle和mysql 批量插入操作
- MyBatis单一和批量操作数据库SQL
- mySql事务_ _Java中怎样实现批量删除操作(Java对数据库进行事务处理)?
- MyBatis中的批量插入、删除数据库数据(MySql和Oracle)
- 数据库--MyBatis的(insert,update,delete)三种批量操作
- jdbc 连接数据库、批量操作、事务(oracle、mysql)
- 数据库操作-表合并-Python连接Mysql-批量修改列属性-csv读入Python
- MyBatis批量操作_MySql
- SpringMVC + Mybatis +JSON + mysql 进行批量插入的实例操作
- mybatis针对Oracle数据库进行(单个或多个条件)批量操作(新增、修改、删除)的sql写法--mysql
- 数据库--MyBatis的(insert,update,delete)三种批量操作
- 安装mysql并通过mybatis进行数据库操作
- Mybaities 批量操作数据库报错,抛MySQLSyntaxErrorException异常
- MyBatis单一和批量操作数据库SQL
- MyBatis批量操作_MySql
- mybatis之mysql&oracle 批量操作
- SSM之Mybatis对数据库的查询以及批量操作
- 总结基于mysql的jdbc对数据库的操作(增删查改,批量操作,事务)
- 终极解决sqlserver、MySQL、Oracle三种数据库模糊查询语句,ssm框架mybatis操作数据库
- redis mongodb mysql 三大数据库的更简单的批量操作。