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

大众服务器网站鸿邑网站建设

大众服务器网站,鸿邑网站建设,武威网站seo,苏州网站建设开发公司foreach遍历集合 collection:指定要遍历的集合 list类型的参数会特殊处理封装在map中#xff0c;map的key就叫list item:将当前遍历出的元素赋值给指定的变量 #{变量名}就能取出变量的值也就是当前遍历出的元素 separator:每个元素之间的分隔符 open:遍历出所有结果拼接一…foreach遍历集合 collection:指定要遍历的集合 list类型的参数会特殊处理封装在map中map的key就叫list item:将当前遍历出的元素赋值给指定的变量 #{变量名}就能取出变量的值也就是当前遍历出的元素 separator:每个元素之间的分隔符 open:遍历出所有结果拼接一个开始的字符 close:遍历出所有结果拼接一个结束的字符 index:索引。遍历list的时候 index就是索引 遍历map的时候index表示的就是map的keyitem就是map的值 public ListEmployee getEmpsByConditionForeach(Param(ids) ListInteger ids);!-- public ListEmployee getEmpsByConditionForeach(Param(ids)ListInteger employee);-- select idgetEmpsByConditionForeach resultTypecom.atguigu.mybatis.bean.Employeeselect * from tb1_employee!--collection:指定要遍历的集合list类型的参数会特殊处理封装在map中map的key就叫listitem:将当前遍历出的元素赋值给指定的变量#{变量名}就能取出变量的值也就是当前遍历出的元素separator:每个元素之间的分隔符open:遍历出所有结果拼接一个开始的字符close:遍历出所有结果拼接一个结束的字符index:索引。遍历list的时候 index就是索引遍历map的时候index表示的就是map的keyitem就是map的值--foreach collectionids itemitem_id separator, open where id in ( close )#{item_id}/foreach/select注意这里的collection只能填list或者是map如果想填ids需要在参数上加Param注解 Testpublic void test02() throws IOException {SqlSessionFactory sqlSessionFactory getSqlSessionFactory();SqlSession sqlSession sqlSessionFactory.openSession();try{EmployeeMapperDynamicSQL mapper sqlSession.getMapper(EmployeeMapperDynamicSQL.class);ListEmployee list mapper.getEmpsByConditionForeach(Arrays.asList(1, 2, 3, 4));for (Employee emp : list){System.out.println(emp);}//手动提交数据sqlSession.commit();}finally {sqlSession.close();}}foreach批量插入 方式一 public void addEmps(Param(emps) ListEmployee emps);insert idaddEmpsINSERT INTO tb1_employee(last_name,email,gender,d_id)valuesforeach collectionemps item emp separator,(#{emp.lastName},#{emp.email},#{emp.gender},#{emp.dept.id})/foreach/insertTestpublic void test04() throws IOException {SqlSessionFactory sqlSessionFactory getSqlSessionFactory();SqlSession sqlSession sqlSessionFactory.openSession();try{EmployeeMapperDynamicSQL mapper sqlSession.getMapper(EmployeeMapperDynamicSQL.class);ListEmployee emps new ArrayList();emps.add(new Employee(null,smitdash,smitadshqq.com,1,new Department(1)));emps.add(new Employee(null,allsadasen,allesadnqq.com,0,new Department(1)));mapper.addEmps(emps);sqlSession.commit();}finally {sqlSession.close();}}方式二 这种方式需要数据库连接属性allowMultiQueriestrue dbconfig.properties: jdbc.urljdbc:mysql://localhost:3306/mybatis?serverTimezoneUTCallowMultiQueriestrueinsert idaddEmpsforeach collectionemps item emp separator;INSERT INTO tb1_employee(last_name,email,gender,d_id)values(#{emp.lastName},#{emp.email},#{emp.gender},#{emp.dept.id})/foreach/insert
http://www.zqtcl.cn/news/693362/

相关文章:

  • 盐亭县建设局网站网站建设基本技术
  • 优化seo网站高质量的邯郸网站建设
  • 网站开发 合同范本软件设计专业介绍
  • 南山网站建设设计莱州网站建设关键字排名优化网络托管微信代运营
  • 传统门户网站有哪些网络营销公司全网推广公司
  • 桥头镇网站建设卢松松外链工具
  • 手机网站导航设计大连市自然资源局
  • 装修网站vr全景图怎么做软件工程师证书报考条件
  • 部门网站建设管理经验交流材料定制开发app
  • 做网站 就google权重查询
  • 网站制作 福宁网络有限公司绚丽的网站
  • wordpress ip 访问重庆seo顾问服务
  • 灰色调网站自动seo系统
  • 河北省网站建设公司排名企业网络信息安全
  • 郑州网站定制建个微商城网站
  • 北京好网站制作公司哪家好vs加数据库做网站
  • 电子商务网站建设与管理第四章答案seo入门培训学校
  • 温州最便宜网站建设有哪些网站可以做推广
  • 郑州网站建设制作公司wordpress播放m3u8
  • wordpress企业站手机客户端wordpress获取主页路径
  • 免费开通的网站外国网站在中国做推广
  • 揭阳公司做网站泰国网站域名
  • 上海网站制作方法北京网站制作设计推广公司
  • 衡水哪有建网站的吗个人简历word模板
  • 网站建设前期开发企业网站开发丨薇
  • 流程图 网站做网站后台数据库建设
  • 免费做英语卷子的网站wordpress去谷歌插件
  • 做网站费用网站极简设计
  • 兰州市建设工程安全质量监督站网站优化公司治理
  • 高质量的合肥网站建设天津百度网站快速优化