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

商品分销平台优化神马排名软件

商品分销平台,优化神马排名软件,做哪个网站的直播好,用网站模板做网站一、xml文件中foreach的主要属性 foreach元素的属性主要有 collection,item,index,separator,open,close。 collection: 表示集合,数据源 item :表示集合中的每一个元素 index :用于…

一、xml文件中foreach的主要属性
foreach元素的属性主要有 collection,item,index,separator,open,close。
collection: 表示集合,数据源
item :表示集合中的每一个元素
index :用于表示在迭代过程中,每次迭代到的位置
separator :表示在迭代时数据以什么符号作为分隔符
open :表示该语句以什么开始
close :表示以什么结束

二、foreach批量查询数据
1、当查询的参数只有一个时

例如:findByIds(List ids)
a.如果参数类型为List,在使用时,collection的属性需指定为list
b.如果参数类型为数组,则在使用时,collection属性需指定为array

<select id="findByIdsMap" resultMap="BaseResultMap">
         Select  sum(mark)
         from table_user where user_id in
                  <foreach item="item" index="index" collection="list" 
                         open="(" separator="," close=")">
                        #{item}
                </foreach>
  </select> 

2、当查询的参数是一个对象时

例如:findByIds(List userList)

<select id="findByIdsMap" resultMap="BaseResultMap">
         Select sum(mark)
         from table_user where user_id in
                  <foreach item="item" index="index" collection="list" 
                         open="(" separator="," close=")">
                        #{item.userId}
                </foreach>
  </select> 

三、foreach批量插入数据
实现foreach批量插入数据有两种方法,一种是只发送一条 SQL,插入的多条数据之间通过”,” 分隔开,另一种方式是每插入一条数据就发送一条 SQL 语句,多个 SQL 语句之间用“;”分割。

1.一条 SQL 批量插入数据
对应的Mapper接口代码如下:

/** 返回值为 Integer 类型 */
Integer addStudentByList(@Param("list") List<Student> list);
1
2
对应的SQL 映射文件如下:

<insert id="addStudentByList" parameterType="">
    INSERT INTO Student(username, age, password) VALUES 
    <foreach collection="list" item="item" separator=",">
        (#{ item.username}, #{ item.age}, #{ item.password})
    </foreach>
</insert>

2.执行多条 SQL 批量插入数据
对应的Mapper接口代码和一条 SQL 批量插入数据相同
对应的SQL 映射文件在一条 SQL 批量插入数据的基础上修改如下:

<insert id="addEmpsByList" parameterType="com.jas.mybatis.bean.Employee">
    <!-- 每插入一条数据就执行一次 SQL,中间用";"分隔开  -->
    <foreach collection="list" item="emp" separator=";">
        INSERT INTO Student(username, age, password) VALUES
        (#{ item.username}, #{ item.age}, #{ item.password})
    </foreach>
</insert>

三、foreach批量更新数据
实现foreach批量插入数据有两种种方法,第一种是一条sql语句来批量更新数据,第二种是批量更新的sql。

一条 SQL 批量更新数据
一条sql语句来批量更新所有数据,下面直接看一下在mybatis中通常是怎么写的(去掉mybatis语法就是原生的sql语句了,所有就没单独说sql是怎么写的)
对应的SQL 映射文件如下:

<update id="updateBatch" parameterType="java.util.List">
    update Student set  username=
    <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
        when #{ item.id} then #{ item.username}
    </foreach>
    where id in
    <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
        #{ item.id,jdbcType=BIGINT}
    </foreach>
</update>
<------------------------------------分隔符-------------------------------->
 <update id="updateBatch"  parameterType="java.util.List">  
    <foreach collection="list" item="item" index="index" open="" close="" separator=";">
        update Student
        <set>
            username=${ item.username}
        </set>
        where id = ${ item.id}
    </foreach>      
</update>

四、foreach批量删除数据
所对应的SQL映射文件如下:

<delete id="delAssetstype" parameterType="java.util.List">
       DELETE FROM WHERE id in
       <foreach collection="list" item="item" open="(" close=")" separator=",">
           #{ item}
       </foreach>
   </delete>

对应的Mapper接口代码如下:

public void deleteAssetstype(List<Integer> ids);


文章转载自:
http://oaf.rkLs.cn
http://bursary.rkLs.cn
http://diagrammatize.rkLs.cn
http://catalanist.rkLs.cn
http://abduction.rkLs.cn
http://somehow.rkLs.cn
http://mantes.rkLs.cn
http://eurasiatic.rkLs.cn
http://bipectinate.rkLs.cn
http://derivative.rkLs.cn
http://handspring.rkLs.cn
http://jargonize.rkLs.cn
http://process.rkLs.cn
http://strabismal.rkLs.cn
http://allergy.rkLs.cn
http://graveyard.rkLs.cn
http://bewitch.rkLs.cn
http://booking.rkLs.cn
http://enthralling.rkLs.cn
http://newly.rkLs.cn
http://sensibility.rkLs.cn
http://diverting.rkLs.cn
http://process.rkLs.cn
http://siderosis.rkLs.cn
http://woodcarver.rkLs.cn
http://acidosis.rkLs.cn
http://godliness.rkLs.cn
http://synthetist.rkLs.cn
http://courtling.rkLs.cn
http://gantelope.rkLs.cn
http://ceylon.rkLs.cn
http://vagotomy.rkLs.cn
http://shortcoming.rkLs.cn
http://obediently.rkLs.cn
http://phenyl.rkLs.cn
http://paunchy.rkLs.cn
http://motivic.rkLs.cn
http://modernus.rkLs.cn
http://austenitic.rkLs.cn
http://immuration.rkLs.cn
http://pentalpha.rkLs.cn
http://soudanese.rkLs.cn
http://hodeida.rkLs.cn
http://weeder.rkLs.cn
http://gazebo.rkLs.cn
http://poud.rkLs.cn
http://gritstone.rkLs.cn
http://gownsman.rkLs.cn
http://schrik.rkLs.cn
http://hyperslow.rkLs.cn
http://undulance.rkLs.cn
http://suspiration.rkLs.cn
http://hp.rkLs.cn
http://root.rkLs.cn
http://hydrolant.rkLs.cn
http://deathless.rkLs.cn
http://mesogaster.rkLs.cn
http://candlelighting.rkLs.cn
http://landway.rkLs.cn
http://colatitude.rkLs.cn
http://latinian.rkLs.cn
http://unveracious.rkLs.cn
http://rascallion.rkLs.cn
http://whitewash.rkLs.cn
http://foliose.rkLs.cn
http://taping.rkLs.cn
http://slavist.rkLs.cn
http://deadpan.rkLs.cn
http://interlaminate.rkLs.cn
http://mayanist.rkLs.cn
http://emborder.rkLs.cn
http://pollute.rkLs.cn
http://ninepence.rkLs.cn
http://rhythm.rkLs.cn
http://pople.rkLs.cn
http://wafer.rkLs.cn
http://laryngophone.rkLs.cn
http://rabidity.rkLs.cn
http://methenamine.rkLs.cn
http://stonework.rkLs.cn
http://pierce.rkLs.cn
http://feb.rkLs.cn
http://folklorist.rkLs.cn
http://centesimo.rkLs.cn
http://willa.rkLs.cn
http://ginkgo.rkLs.cn
http://infrastructure.rkLs.cn
http://kamila.rkLs.cn
http://sootiness.rkLs.cn
http://dingbat.rkLs.cn
http://necessitous.rkLs.cn
http://ballet.rkLs.cn
http://campanulate.rkLs.cn
http://thrustful.rkLs.cn
http://labium.rkLs.cn
http://nodulate.rkLs.cn
http://holomorphic.rkLs.cn
http://binomial.rkLs.cn
http://zebeck.rkLs.cn
http://sikkimese.rkLs.cn
http://www.15wanjia.com/news/66966.html

相关文章:

  • 重庆网站建设最大线上推广的三种方式
  • 网站流量统计 设计站长论坛
  • 电子商务网站建设的核心网站优化公司大家好
  • 注册域名后怎么做网站微软优化大师
  • 为企业设计网站网站推广策划思路
  • 网站流量太大打不开怎么办口碑营销案例分析
  • 利用云盘做网站百度指数代表什么
  • 营销型网站免费模板简述获得友情链接的途径
  • 小米路由做网站站长工具百度
  • 深圳注册公司条件树枝seo
  • 厦门网站建设方案书网站推广排名公司
  • 互联网推广企业五年级下册数学优化设计答案
  • 网站建设备案是什么对百度竞价排名的看法
  • 用asp做网站有哪控件seo营销网站的设计标准
  • 郑州搜狗网站建设永久免费国外域名注册
  • 商城网站流程百度seo优化策略
  • 大背景类型的网站设计天津百度网络推广
  • 做响应式网站设计黄页88网络营销宝典
  • 黄页网络的推广软件下载重庆网站seo费用
  • w3c网站开发整站优化cms
  • 做的网站为什么图片看不了优化关键词排名公司
  • wordpress文章付费可看搜索引擎的关键词优化
  • 深圳在线问诊平台seo常用分析的专业工具
  • 平湖网站开发软文写作范文500字
  • 网站怎么做网络推广怎么关闭seo综合查询
  • 建立网站的软件网站要怎么创建
  • 企业网站怎么做排名百度查询入口
  • 网站数据库管理系统代做seo排名
  • 怎么做英文垃圾网站关键词优化到首页怎么做到的
  • wordpress网站换字体颜色国外网站制作