mainlist 、mainListLeft 为已存在 list,此函数为汇总 mainlist 的内容到 mainListLeft 中
void gather()
{
mainListLeft.Clear();
var query = from item in mainList
group item by new {
item.productCode,
item.productName,
item.number,
} into g
select new Entity
{
productCode = g.Key.productCode,
productName = g.Key.productName,
number = g.Sum(p => p.number),
};
mainListLeft = query.ToList();
}
注:将原List通过 group by 的方式汇总成新的list,需要汇总计算的变量需为decimal类型
启动类添加扫描模板
@MapperScan("–.--.–.--.mapper")
@ComponentScan(–)
扫描:.xml文件 路径;例如 com.gwm.lms.asm.checked.mapper
@扫描注解 @Component @Controller @Service @Repository等等
@Mapper 一定要有,否则 Mybatis 找不到 mapper。
@Repository 可有可无,可以消去依赖注入的报错信息。
@MapperScan 可以替代 @Mapper。
@Component 和 @Repository 效果都是一样的,只是为了声明为bean