1.mybatis传入map参数,map中包含list:

List<FukaModel> fukaModels = price.getSchemaPrice().getFukaList();

Map<String, Object> objectMap = new HashMap<>();

objectMap.put("schemaId", schemaId);

objectMap.put("list", fukaModels);

sqlSession.insert("cn.jj.mall.service.store.insertFukaData",objectMap);

<select id="insertFukaData" parameterType="map" >

<foreach collection="list" item="item" index="index" open="" separator=";" close="">

INSERT INTO jj_fokas_deduct (price_schema_id,min_num, max_num, user_grade)

VALUES (#{schemaId},0,#{item.num},#{item.userGrade})

</foreach>

</select>

2.

List<JjActivityRecommendSku> activityRecommendSkuList = new ArrayList<>();

sqlSession.insert("cn.jj.mall.service.insertActivityRecommendSkuList", activityRecommendSkuList);

<insert id="insertActivityRecommendSkuList" parameterType="cn.jj.mall.model.JjActivityRecommendSku" >

insert into jj_shop.jj_activity_recommend_sku (rec_sku_id, activity_id, sku_id,

sku_sort_order)

values

<foreach collection="list" item="item" index="index" separator=",">

(#{item.recSkuId,jdbcType=INTEGER}, #{item.activityId,jdbcType=INTEGER}, #{item.skuId,jdbcType=VARCHAR},

#{item.skuSortOrder,jdbcType=INTEGER})

</foreach>

</insert>

3.

<update id="unShelveGoodsSku" parameterType="java.util.List">

update jj_shop.jj_goods_sku set status = 5 where status = 4 and sku_id in

<foreach item="item" index="index" collection="list"

open="(" separator="," close=")">

#{item}

</foreach>

</update>

4.

List<String> skuIds = s.selectList(statement,param);

Map<String, Object> map = new HashMap<>();

map.put("storeId",storeId);

map.put("devType",devType);

map.put("list",skuIds);

WHERE SkuId In

<foreach item="sku_id" collection="list" index="index" open="(" separator="," close=")">

#{sku_id}

</foreach>

5.lambda表达式

currencyDataListTemp.stream().collect(Collectors.groupingBy(o-> new CurrencyData(o.getCurrencyDtID(),o.getCurrencyAtID(),o.getCurrencyOriID(),o.getCurrencyName()),Collectors.summingInt(o->o.getReturnAmount()))).forEach((k,v)->{

k.setReturnAmount(v);

currencyDataList.add(k);

});

重写CurrencyData的hash和equals方法:

@Override

public boolean equals(Object o) {

if (this == o) return true;

if (o == null || getClass() != o.getClass()) return false;

CurrencyData currencyData = (CurrencyData) o;

return Objects.equals(currencyDtID, currencyData.currencyDtID) &&

Objects.equals(currencyAtID, currencyData.currencyAtID) &&

Objects.equals(currencyOriID, currencyData.currencyOriID) &&

Objects.equals(currencyName, currencyData.currencyName) &&

Objects.equals(returnAmount, currencyData.returnAmount);

}

@Override

public int hashCode() {

return Objects.hash(currencyDtID, currencyAtID, currencyOriID,currencyName);

}

6.

public static <T>List<T> checkListRepeat(List<T> list) {

return list.stream()

.collect(Collectors.toMap(k -> k, v -> 1, (a, b) -> a + b))

.entrySet().stream()

.filter(entry -> entry.getValue() > 1)

.map(Map.Entry::getKey)

.collect(Collectors.toList());

}

7.

List<Test> list = new ArrayList<>();

//        list.add(new Test("一年级二班", "小明"));

list.add(new Test("一年级二班啊", "小芳"));

list.add(new Test("一年级二班", "小华"));

list.add(new Test("一年级三班啊", "翠花"));

list.add(new Test("一年级三班", "香兰"));

// 集合中对象属性转map

Map<String, String> map = list.stream().collect(Collectors.toMap(Test :: getClassName, Test :: getStudentName));

8.

double sumRate = lotteryProbList.stream().mapToDouble(Double::doubleValue).sum();

9.

Map<String, List<CommodityInfo>> listMap = commodityInfoList.stream().collect(Collectors.groupingBy(model -> model.getCommodityId()));

Mybatis工作原理

mybatis查询foreach使用的更多相关文章

  1. MyBatis的foreach查询(List、Array、Map)

    mybatis 中 foreach collection的三种用法 foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有 item,index ...

  2. mybatis中foreach的用法(转)

    foreach一共有三种类型,分别为List,[](array),Map三种. foreach属性 属性 描述 item 循环体中的具体对象.支持属性的点路径访问,如item.age,item.inf ...

  3. mybatis 查询 xml list参数

    mybatis 查询 xml list参数: <select id="getByIds" resultType="string" parameterTyp ...

  4. mybatis之foreach用法

    在做mybatis的mapper.xml文件的时候,我们时常用到这样的情况:动态生成sql语句的查询条件,这个时候我们就可以用mybatis的foreach了 foreach元素的属性主要有item, ...

  5. mybatis的foreach写用法

    一.mybatis查询 public abstract List<Model> findByIds(@Param("ids")List<Integer> i ...

  6. MySQL和mybatis查询相关

    0.mybatis的xml文件头 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapp ...

  7. mybatis map foreach遍历

    mybatis map foreach遍历 转至http://www.cnblogs.com/yg_zhang/p/4314602.html mybatis 遍历map实例 map 数据如下 Map& ...

  8. MyBatis 查询映射自定义枚举

    背景                  MyBatis查询若想映射枚举类型,则需要从 EnumTypeHandler 或者 EnumOrdinalTypeHandler 中选一个来使用         ...

  9. mybatis查询异常-Error querying database. Cause: java.lang.ClassCastException: org.apache.ibatis.executor.ExecutionPlaceholder cannot be cast to java.util.List

    背景,mybatis查询的时候直接取的sqlsession,没有包装成SqlSessionTemplate,没有走spring提供的代理. 然后我写的获取sqlsession的代码没有考虑到并发的情况 ...

随机推荐

  1. OSG节点访问和遍历

    遍历节点树:osg::Node类中有两个辅助函数: void ascend(NodeVisitor& nv) //虚函数,向上一级节点推进访问器 void traverse(NodeVisit ...

  2. 0.9.0.RELEASE版本的spring cloud alibaba nacos+feign实例

    这里的feign依然是原来的feign,只不过将注册中心由eureka换成了nacos.服务提供方参见0.9.0.RELEASE版本的spring cloud alibaba nacos实例,消费方跟 ...

  3. HashSet的实现原理,简单易懂

    HashSet的实现原理,简单易懂   答: HashSet实际上是一个HashMap实例,都是一个存放链表的数组.它不保证存储元素的迭代顺序:此类允许使用null元素.HashSet中不允许有重复元 ...

  4. logging日志管理

    日志:记录系统运行时的信息的(调试信息和异常信息) 基本用法: import logging logging.debug("这是一条调试信息") logging.info(&quo ...

  5. jq删除标签

    <script>$(function(){ $("div").remove()})</script>

  6. PAT 甲级 1058 A+B in Hogwarts (20 分) (简单题)

    1058 A+B in Hogwarts (20 分)   If you are a fan of Harry Potter, you would know the world of magic ha ...

  7. activity 工作流

    https://blog.csdn.net/cs_hnu_scw/article/details/79059965 https://blog.csdn.net/xnf1991/article/deta ...

  8. pycharm连接linux创建django工程

    windows中安装最新版pycharm--2018年10月的版本 点击创建工程,看下图: C:\Users\Lenovo\PycharmProjects\untitled4 这个路径不要动,一动就出 ...

  9. mysql使用truncate截断带有外键的表时报错--解决方案

    报错内容如:1701 - Cannot truncate a table referenced in a foreign key constraint 一.为什么要使用truncate 使用trunc ...

  10. python介绍,计算机组成。内存分布,进制,操作系统介绍

    学习小方法 ​三个W一个Hwwwh:what(是什么) why(为什么) where(怎么用) how(如何用) 来思考知识点多练,多写,多敲代码增加熟练度与代码量​ Python 是一门面向后台的编 ...