通过自动回复机器人学Mybatis---加强版
中级
53657人学
9.8分
-
-
qq_羽悦_03291187
2021-05-28
- sqlSession+mybatis批量插入

-
0赞 · 0采集
-
-
qq_羽悦_03291187
2021-05-28
- addBatch一条条新增

-
0赞 · 0采集
-
-
qq_羽悦_03291187
2021-05-28
一条一条新增
-
0赞 · 0采集
-
-
钢管舞学员
2021-03-19
- Seperator去去除两边的,
-
截图
0赞 · 0采集
-
-
钢管舞学员
2021-03-19
- 插入多条的xml配置
-
截图
0赞 · 0采集
-
-
钢管舞学员
2021-03-19
- Mysql多条插入的语句
-
截图
0赞 · 0采集
-
-
钢管舞学员
2021-03-19
- 通过循环添加statement.addbatch(),然后统一执行就好了
-
截图
0赞 · 0采集
-
-
qq_新月古城_0
2018-01-17
- 单行插入和批量新增
-
截图
0赞 · 0采集
-
-
波阿斯
2017-12-27
- MYSQL 批量插入语句
-
截图
0赞 · 0采集
-
-
慕UI9362156
2017-11-20
- 批量新增
-
截图
0赞 · 0采集
-
-
nize1989
2017-10-25
- jdbc中如何批量新增插入语句
1、在循环末尾加上statement.addBatch();
2、结束后再执行statement.executeBatch();
-
截图
0赞 · 0采集
-
-
木木嗷
2017-10-23
- 相关代码——(上):
@CommandContent.xml
<insert id="insertOne" parameterType="com.imooc.bean.CommandContent">
insert into COMMAND_CONTENT(CONTENT,COMMAND_ID) values(#{content},#{commandId})
</insert>
<insert id="insertBatch" parameterType="java.util.List">
insert into commandcontent(content,commandId) values
<foreach collection="list" item="item" separator=",">
(#{item.content},#{item.commandId})
</foreach>
</insert>
@ICommandContent.java
public interface ICommandContent {
//单条新增
public void insertOne(CommandContent content);
//批量新增
void insertBatch(List<CommandContent> contentList);
}
-
0赞 · 0采集
-
-
木木嗷
2017-10-23
- 相关代码——(中):
@CommandContentDao.java
/**
* 和command_content表相关的数据库操作
*/
public class CommandContentDao {
//使用jdbc批量增加
public void insertBatchByJdbc(List<CommandContent> contetnList){
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/micro_message?characterEncoding=utf-8", "root",
"root");
String insertSql="insert into command_content(content,command_id) values(?,?)";
PreparedStatement ps = conn.prepareStatement(insertSql);
for(CommandContent c:contetnList){
ps.setString(1,c.getContent());
ps.setInt(2, c.getCommandId());
// ps.executeUpdate();//方法一:不推荐
ps.addBatch();//方法二
}
ps.executeBatch();//方法二
} catch (Exception e) {
e.printStackTrace();
}
}
}
-
0赞 · 0采集
-
-
木木嗷
2017-10-23
- 相关代码——(下):
@CommandContentDao.java
/**
* 和command_content表相关的数据库操作
*/
public class CommandContentDao {
//使用mybatics批量新增
public void insertBatch(List<CommandContent> contentlList){
DBAccess dbAccess=new DBAccess();
try {
SqlSession sqlSession=dbAccess.getSqlSession();
//通过sqlSession执行SQL语言
ICommandContent commandContent = sqlSession.getMapper(ICommandContent.class);
commandContent.insertBatch(contentlList);
sqlSession.commit();
} catch (IOException e) {
e.printStackTrace();
}
}
}
-
0赞 · 0采集
-
-
霜花似雪
2017-10-07
- 在jdbc中批量插入可以遍历循环一次次插入边执行,这样效率很不好,所以使用addBatch(),然后执行executeBatch(),那么在mybatis中如何实现批量插入的呢?mybatis是要自己在配置文件配置sql语句,所以根据mysql数据库的insert语句拼接出相应的sql,insert into 表名 values(数据1,数据2…),(数据1,数据2…),…即可,所以传入的参数是list,最后forEach标签循环出来数据拼接sql语句
<foreach collection=”lsit” item=”item” separator="," >
(#{item.content},#{item.commandId})
</foreach>
-
截图
0赞 · 0采集
-
-
霜花似雪
2017-10-07
- JDBC实现批量插入
-
截图
0赞 · 0采集
-
-
Zhq9695
2017-09-08
- JDBC实现批量新增
-
截图
0赞 · 0采集
-
-
Judas2
2017-07-28
- mybatis实现批量新增插入DAO层实现,直接将传过来的list执行对应的插入方法就行,不用再循环了
-
截图
0赞 · 0采集
-
-
Judas2
2017-07-28
- 批量新增 接口代码
-
截图
0赞 · 0采集
-
-
Judas2
2017-07-28
- mybatis在xml配置文件中实现批量新增:
<!--collection="list" 这个list表明传过来的是list, 而item="item" 这个item可以随便写; 参数要用,逗号分隔 -->
<insert id="insertBatch" parameterType="java.util.List" >
insert into COMMAND_CONTENT(CONTENT,COMMAND_ID) values
<foreach collection="list" item="item" separator=",">
(#{item.content},#{item.commandId})
</foreach>
</insert>
-
截图
0赞 · 0采集
-
-
Judas2
2017-07-28
- 同时插入多条数据的sql如何写:
insert into command_content(content,command_id) values ("呵呵",1),("哈哈",2);
-
0赞 · 0采集
-
-
Judas2
2017-07-28
- JDBC实现批量新增: 先执行addBatch();
等多条数据都加入成功之后再执行 statement.executeBatch();
-
截图
0赞 · 0采集
-
-
Judas2
2017-07-28
- JDBC实现批量新增
-
截图
0赞 · 0采集
-
-
DR枫林残忆
2017-05-20
- @CommandContent.xml
<insert id="insertOne" parameterType="com.imooc.bean.CommandContent">
insert into COMMAND_CONTENT(CONTENT,COMMAND_ID) values(#{content},#{commandId})
</insert>
<insert id="insertBatch" parameterType="java.util.List">
insert into commandcontent(content,commandId) values
<foreach collection="list" item="item" separator=",">
(#{item.content},#{item.commandId})
</foreach>
</insert>
@ICommandContent.java
public interface ICommandContent {
/**
* 单条新增
*/
public void insertOne(CommandContent content);
/**
* 批量新增
*/
void insertBatch(List<CommandContent> contentList);
}
Ps1:注意:批量新增不同的SQL有不同的语法。(这里针对MySQL)
Ps2:separator=",":会加在中间,不会加在头尾。
-
0赞 · 0采集
-
-
JarvanIV
2017-02-24
- 批量新增
-
截图
0赞 · 0采集
-
-
慕粉4117368
2017-01-11
- @CommandContent.xml
<insert id="insertOne" parameterType="com.imooc.bean.CommandContent">
insert into COMMAND_CONTENT(CONTENT,COMMAND_ID) values(#{content},#{commandId})
</insert>
<insert id="insertBatch" parameterType="java.util.List">
insert into commandcontent(content,commandId) values
<foreach collection="list" item="item" separator=",">
(#{item.content},#{item.commandId})
</foreach>
</insert>
@ICommandContent.java
public interface ICommandContent {
/**
* 单条新增
*/
public void insertOne(CommandContent content);
/**
* 批量新增
*/
void insertBatch(List<CommandContent> contentList);
}
Ps1:注意:批量新增不同的SQL有不同的语法。(这里针对MySQL)
Ps2:separator=",":会加在中间,不会加在头尾。
-
0赞 · 0采集
-
-
夜还没黑
2017-01-03
- 相关代码——(下):
@CommandContentDao.java
/**
* 和command_content表相关的数据库操作
*/
public class CommandContentDao {
//使用mybatics批量新增
public void insertBatch(List<CommandContent> contentlList){
DBAccess dbAccess=new DBAccess();
try {
SqlSession sqlSession=dbAccess.getSqlSession();
//通过sqlSession执行SQL语言
ICommandContent commandContent = sqlSession.getMapper(ICommandContent.class);
commandContent.insertBatch(contentlList);
sqlSession.commit();
} catch (IOException e) {
e.printStackTrace();
}
}
}
-
0赞 · 0采集
-
-
夜还没黑
2017-01-03
- 相关代码——(中):
@CommandContentDao.java
/**
* 和command_content表相关的数据库操作
*/
public class CommandContentDao {
//使用jdbc批量增加
public void insertBatchByJdbc(List<CommandContent> contetnList){
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/micro_message?characterEncoding=utf-8", "root",
"root");
String insertSql="insert into command_content(content,command_id) values(?,?)";
PreparedStatement ps = conn.prepareStatement(insertSql);
for(CommandContent c:contetnList){
ps.setString(1,c.getContent());
ps.setInt(2, c.getCommandId());
// ps.executeUpdate();//方法一:不推荐
ps.addBatch();//方法二
}
ps.executeBatch();//方法二
} catch (Exception e) {
e.printStackTrace();
}
}
}
-
0赞 · 0采集
-
-
夜还没黑
2017-01-03
- 相关代码——(上):
@CommandContent.xml
<insert id="insertOne" parameterType="com.imooc.bean.CommandContent">
insert into COMMAND_CONTENT(CONTENT,COMMAND_ID) values(#{content},#{commandId})
</insert>
<insert id="insertBatch" parameterType="java.util.List">
insert into commandcontent(content,commandId) values
<foreach collection="list" item="item" separator=",">
(#{item.content},#{item.commandId})
</foreach>
</insert>
@ICommandContent.java
public interface ICommandContent {
//单条新增
public void insertOne(CommandContent content);
//批量新增
void insertBatch(List<CommandContent> contentList);
}
-
0赞 · 0采集
-
-
Anthonyxd
2016-12-21
- jdbc批量新增
-
截图
0赞 · 0采集