当前位置: 首页 > wzjs >正文

深圳网站制作费用网站导航用什么字体

深圳网站制作费用,网站导航用什么字体,wordpress右上角登录,怎样注册网站中文域名最近碰到几道Mybatis3的面试题&#xff0c;记录下。 1.Mybatis3 怎样执行批量插入&#xff1f; 使用Mybatis3中的<foreach>标签动态拼接需要插入的记录行数据。 基本语法复习&#xff0c;MySQL批量插入SQL如下&#xff1a; INSERT INTO user(user_name, age, created_…

最近碰到几道Mybatis3的面试题,记录下。

1.Mybatis3 怎样执行批量插入?

使用Mybatis3中的<foreach>标签动态拼接需要插入的记录行数据。

基本语法复习,MySQL批量插入SQL如下:

INSERT INTO `user`(user_name, age, created_by, updated_by)
VALUES 
('chen', 2, 'derek', 'derek'),
('chen', 2, 'derek', 'derek')

 插入多态语句时,在values后用括号把要插入的数据包围,同时用逗号分隔每条记录。

还是使用user表来实践下。

CREATE TABLE `user` (`USER_ID` int NOT NULL AUTO_INCREMENT,`USER_NAME` varchar(100) NOT NULL COMMENT '用户姓名',`AGE` int NOT NULL COMMENT '年龄',`CREATED_TIME` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,`CREATED_BY` varchar(100) NOT NULL DEFAULT 'UNKNOWN',`UPDATED_TIME` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,`UPDATED_BY` varchar(100) NOT NULL DEFAULT 'UNKNOWN',PRIMARY KEY (`USER_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=345 DEFAULT CHARSET=utf8mb3

UserMapper.java接口定义如下:

public class UserMapper {int batchInsertUsers(@Param("users") List<User> users);
}

Mybatis3 批量插入时,需要注意插入的最后一个逗号的清除,所以使用<trim>标签来处理比较好。

User Mapper.xml定义如下:

<insert id="batchInsertUsers" parameterType="list">INSERT INTO `user`(user_name, age, created_by, updated_by)<trim prefix="VALUES" suffixOverrides=","><foreach collection="users" index="index" item="user" separator=",">(#{user.userName, jdbcType=VARCHAR},#{user.age, jdbcType=INTEGER},#{user.createdBy, jdbcType=VARCHAR},#{user.updatedBy, jdbcType=VARCHAR})</foreach></trim>
</insert>

测试代码如下:

package com.derek.mapper;import com.derek.model.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;public class UserMapperTest {private static SqlSessionFactory sqlSessionFactory;private static SqlSession sqlSession;private static UserMapper userMapper;@BeforeAllpublic static void setUp() throws IOException {Reader reader = Resources.getResourceAsReader("mybatis-config.xml");sqlSessionFactory = new org.apache.ibatis.session.SqlSessionFactoryBuilder().build(reader);sqlSession = sqlSessionFactory.openSession();userMapper = sqlSession.getMapper(UserMapper.class);}@AfterAllpublic static void tearDown() {userMapper = null;sqlSession.close();}@Testpublic void testInsertBatch() {List<User> users = new ArrayList<>();for(int i=1; i<=10; i++) {User user = new User();user.setUserName("batch name-" + i);user.setAge(i);user.setCreatedBy("robot");user.setCreatedTime(new Date());user.setUpdatedBy("robot");user.setUpdatedTime(new Date());users.add(user);}userMapper.batchInsertUsers(users);sqlSession.commit();}}

2.Mybatis3 怎样执行批量操作(插入/更新/删除)?

使用 ExecutorType.BATCH 模式

SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);

然后进行批量插入/更新/删除操作,再进行提交。

具体的示例如下:

1)插入100条user记录。

2)修改100条user记录。

3)删除100条user记录。

把上述300条操作做成一个batch执行。

@Testpublic void testBatchOperation() {try (SqlSession batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH)) {UserMapper userMapper = batchSession.getMapper(UserMapper.class);// insert 100 usersfor(int i=1; i<=100; i++) {User user = new User();user.setUserName("batch name-" + i);user.setAge(i);user.setCreatedBy("robot");user.setCreatedTime(new Date());user.setUpdatedBy("robot");user.setUpdatedTime(new Date());userMapper.insert(user);}// update 100 usersUserExample userExample = new UserExample();userExample.createCriteria().andUserNameLike("%batch name%");User updatedUser = new User();updatedUser.setUserName("updated name");userMapper.updateByExampleSelective(updatedUser, userExample);// delete 100 usersUserExample deleteExample = new UserExample();deleteExample.createCriteria().andUserNameLike("updated name");userMapper.deleteByExample(deleteExample);// commit the batchbatchSession.commit();
}


文章转载自:

http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://00000000.gjpcL.cn
http://www.dtcms.com/wzjs/602201.html

相关文章:

  • 靖州建设局网站扬州网站建设icp备
  • 做电影网站赚钱知乎四川德充建设集团有限公司网站
  • 设计网站名称电商网站商品详情页
  • 备案ip 查询网站渭南做网站
  • 怎么做简单的钓鱼网站百度广告代理公司
  • 洮南网站建设中国建设
  • 基于html5的旅游网站开发直播软件怎么开发
  • 网站开发软硬件wordpress本地怎么搬家
  • 网站公司的利润外贸做中英文网站
  • 宁波网站建设服务报价企业年报
  • 奥运会网站制作电脑上怎么做网站
  • 青州做网站的电话一站式做网站费用
  • 公司网站建设多少费用哪儿济南兴田德润联系电话成都微官网制作
  • 好网站wordpress 主题 主机
  • 做ppt好的模板下载网站有哪些h5游戏网站建设
  • 做网站认证对网站有什么好处社交网站建设码
  • 吴江规划建设局网站百度一下生活更好
  • 微商推广网站怎么做金华网站制作企业
  • 衡水企业网站设计报价所见即所得网站管理系统
  • 宁波市建设局网站wordpress 移动模板
  • 天津做公司网站自己做的网站打开太慢
  • 网站开发需要懂哪些网络维护工作总结范文
  • 北京未来科技城开发建设有限公司 网站奉贤网页设计
  • 网站建设备案信息无锡网站制作专业服务公司
  • 建设局网站查询线上网站设计培训
  • 使用angularjs的网站做网站背景的图片大小
  • 建站公司分析2018一级a做爰片免费网站
  • 骨干专业建设验收网站江苏省二级建造师考试网
  • 网站策划布局专业模板网站制作服务
  • 个人网站建设实训目的动漫设计培训机构哪里好