mybatis 之 parameterType="HashMap"参数包含list
/**
* 获得人气组合商品详情
* @param paramMap
* @return
*/
public List<Goods> getCheckGoodsCombination(Map paramMap);
/**
* 获得人气组合商品详情
*
* @param request
* @param response
* @param originalGoodsId
* @param checkGoodsIds
*/
@RequestMapping("/combination")
public void combination(HttpServletRequest request, HttpServletResponse response,
@RequestParam(value = "originalGoodsId", required = true) String originalGoodsId,
@RequestParam(value = "checkGoodsId", required = false) String checkGoodsIds) {
try {
ServiceMessage<List<Goods>> combinationResult = goodsDetailService.getCheckGoodsCombination(originalGoodsId, checkGoodsIds);
if (combinationResult.getStatus() != MsgStatus.NORMAL) {
this.setResultInfo(combinationResult.getStatus().getCode(), combinationResult.getMessage());
return;
}
List<Goods> goodsList = combinationResult.getResult();
DecimalFormat df = new DecimalFormat("0.00");
BigDecimal sumMarktPrice = new BigDecimal(0);
BigDecimal sumEcPrice = new BigDecimal(0);
for (Goods g : goodsList) {
// 如果是促销
if (g.getDiscountState().equals("enable")) {
long beginTime = DateUtils.dateAllToLong(g.getBeginTime());
long endTime = DateUtils.dateAllToLong(g.getEndTime());
long current = System.currentTimeMillis();
if (beginTime > current || endTime < current) {
g.setDiscountState("none");
}else{
g.setEcPrice(g.getDiscountPrice());
}
sumEcPrice = sumEcPrice.add(g.getEcPrice());
} else {
sumEcPrice = sumEcPrice.add(g.getEcPrice());
}
sumMarktPrice = sumMarktPrice.add(g.getMarketPrice());
// 转化为小数点两位
g.setEcPrice(new BigDecimal(df.format(g.getEcPrice())));
}
// 优惠价=网售价-市场价
BigDecimal promotePrice = sumEcPrice.subtract(sumMarktPrice);
//
_result.put("originalGoodsId", originalGoodsId);
// 优惠的价
_result.put("promotePrice", df.format(promotePrice));
// 组合售价之和
_result.put("combinationPrice", df.format(sumEcPrice));
// 组合结果集
_result.put("combinationResult", combinationResult.getResult());
_result.setMsg(combinationResult.getMessage());
_result.setStatus(combinationResult.getStatus().getCode());
} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
write(request, response);
}
}
/**
* 获得人气组合商品详情
*
* @param originalGoodsId 原goodsId
* @param checkGoodsIds 选中的组合goodsId
* @return
*/
@Override
public ServiceMessage<List<Goods>> getCheckGoodsCombination(String originalGoodsId, String checkGoodsIds) {
try {
List<String> list = new ArrayList<String>();
String combinationType = "";
if (!"".equals(checkGoodsIds) && checkGoodsIds != null) {
if (checkGoodsIds.equals("0")) {
combinationType = "original";
} else {
combinationType = "combination";
checkGoodsIds = URLDecoder.decode(checkGoodsIds, "utf-8");
String[] checkArr = checkGoodsIds.split(",");
for (int i = 0; i < checkArr.length; i++) {
list.add(checkArr[i]);
}
}
} else {
list = null;
combinationType = "all";
//return super.returnParamsError("人气组合选中的组合checkGoodsIds为空");
}
if (originalGoodsId == null || "".equals(originalGoodsId)) {
return super.returnParamsError("人气组合原goodsId为空");
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("originalGoodsId", originalGoodsId);
map.put("checkGoodsIds", list);
map.put("combinationType", combinationType);
List<Goods> combinationList = goodsMapper.getCheckGoodsCombination(map);
if (combinationList == null || combinationList.size() < 1) {
return super.returnException("查找不到人气组合商品");
}
return super.returnCorrectResult(combinationList);
} catch (Throwable e) {
logger.error(e);
return super.returnException("查询人气组合商品出错");
}
}
mybatis 之 parameterType="HashMap"参数包含list的更多相关文章
- MyBatis的parameterType传入参数类型
在mybatis映射接口的配置中,有select,insert,update,delete等元素都提到了parameterType的用法,parameterType为输入参数,在配置的时候,配置相应的 ...
- mybatis mapper文件sql语句传入hashmap参数
1.怎样在mybatis mapper文件sql语句传入hashmap参数? 答:直接这样写map就可以 <select id="selectTeacher" paramet ...
- Mybatis学习笔记——输入参数parameterType、Mybatis调用存储过程
输入参数:parameterType(两种取值符号) 1.类型为简单类型 区别: (1) #{可以为任意值} ${vaue}--->标识符只能是value (2) ...
- MyBatis传入多个参数的问题
一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...
- mybatis传入多个参数
一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...
- [转]MyBatis传入多个参数的问题 - mingyue1818
原文 http://www.cnblogs.com/mingyue1818/p/3714162.html 一.单个参数: public List<XXBean> getXXBeanLis ...
- (转载)MyBatis传入多个参数的问题
原文地址:https://www.cnblogs.com/mingyue1818/p/3714162.html 一.单个参数: public List<XXBean> getXXBeanL ...
- mybatis 传入多个参数
一.单个参数: public List<XXBean> getXXBeanList(@param("id")String id); <select id=&quo ...
- MyBatis传入多个参数的问题(转)
一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...
随机推荐
- SSD 固态硬盘,Trim指令 ,查看状态、开启、关闭
一说到SSD 固态硬盘,经常会看到Trim指令这个名词,那什么是Trim? Trim是什么? 为了解决硬盘降速的问题,微软联合各大SSD厂商开发了一个新技术——Trim.Trim指令也叫disab ...
- TCP滑动窗口协议
TCP的首部中有一个很重要的字段就是16位长的窗口大小,它出现在每一个TCP数据报中,配合32位的确认序号,用于向对端通告本地socket的接收窗口大小.也就是说,如果本地socket发送一个TCP ...
- hashMap put方法 第三行代码
inflateTable(threshold) 分析: Hi.java public class Hi { //临界值(一个值最接近2的n次幂的数,比如7的临界值为8) int threshold; ...
- hostapd作为radius服务器
使用hostapd作为radius服务器,用于企业wifi加密认证. 参考链接: http://www.cnblogs.com/claruarius/p/5902141.html 去网上下载hosta ...
- JDBC排序数据实例
在本教程将演示如何在JDBC应用程序中,从数据库表中查询数据记录,在查询语句中将使用asc和desc关键字按升序或降序对记录进行排序.在执行以下示例之前,请确保您已经准备好以下操作: 具有数据库管理员 ...
- JDBC Statements, PreparedStatement和CallableStatement语句
当获得了与数据库的连接后,就可以与数据库进行交互了. JDBC Statement,CallableStatement和PreparedStatement接口定义了可用于发送SQL或PL/SQL命令, ...
- MyBatis整合Spring MVC
前面几篇文章已经讲到了mybatis与spring 的集成.目前主流的Web MVC框架,除了Struts这个主力外,还有Spring MVC,主要是由于 Spring MVC 配置比较简单,使用起来 ...
- (转)TCP连接异常断开检测
TCP是一种面向连接的协议,连接的建立和断开需要通过收发相应的分节来实现.某些时候,由于网络的故障或是一方主机的突然崩溃而另一方无法检测到,以致始终保持着不存在的连接.下面介绍一种方法来检测这种异常断 ...
- Linux定时任务工具crontab详解及系统时间同步
Linux配置自动时间同步 linux下时间同步的两种方法分享 tail -f /var/log/cron linux下定时执行任务的方法 在LINUX中你应该先输入crontab -e,然后就会有 ...
- 纯CSS3实现牛奶般剔透的3D按钮特效
今天我们要来看一款非常特别的纯CSS3 3D按钮,它的外观酷似纯白剔透的牛奶,点击按钮的时候还会出现一种很柔和的弹力效果.按钮按下时,按钮会轻轻的弹动一下,非常逼真.本文我们在观赏演示的同时,也将源代 ...