发表于: 2017-10-22 22:23:45
1 663
今天完成的事情:
1.编写产品接口
@RequestMapping(value = "/a/product/condition/search", method = RequestMethod.GET)
public String getProductList(HttpServletRequest request, HttpServletResponse response,
ModelMap model, Integer page, Integer size, String name,
Integer interestBeginAt, BigDecimal minYearRate,
BigDecimal maxYearRate, BigDecimal minAmount, Integer status,
Integer minMonthLimit, Integer maxMonthLimit, String code,
Integer timeLimitType) {
log.info("method getProductList() begin...");
if (page == null) {
page = 1;
}
if (size == null) {
size = 10;
}
int start = (page - 1) * size;
if (start < 0) {
start = 0;
}
int total = 0, totalPage = 0;
log.info("arguments: name = [" + name + "], interestBeginAt = [" + interestBeginAt
+ "], minYearRate = [" + minYearRate + "], maxYearRate = [" + maxYearRate
+ "], minAmount = [" + minAmount + "], status = [" + status + "], minMonthLimit = ["
+ minMonthLimit + "], maxMonthLimit = [" + maxMonthLimit + "], code = [" + code
+ "], timeLimitType = [" + timeLimitType + "]");
log.info("productList page paramer is: page = " + page + ", size = " + size);
try {
/* 第一步、动态拼接sql,并对参数合法性校验 */
Map<String, Object> params = ProductUtil.getProductListParam(name, interestBeginAt,
minYearRate, maxYearRate, minAmount, status, minMonthLimit, maxMonthLimit, code,
timeLimitType);
log.info("dynamic condition params is: " + params);
if (params.containsKey("error")) {
log.info("params contain error key");
model.addAttribute("code", params.get("error"));
return "/data/json";
}
/* 第二步、条件查询产品列表 */
List<Long> ids = productService.getIdsByDynamicCondition(Product.class, params, start, size);
log.info("product ids is ===" + ids);
List<Product> productList = new ArrayList<>();
if (CollectionUtils.isEmpty(ids)) {
log.info("product ids is empty");
}
else {
productList = productService.getObjectsByIds(ids);
log.info("product list size is: " + productList.size());
/* 第三步、查询总数 */
total = productService.getIdsByDynamicCondition(Product.class, params, 0, Integer.MAX_VALUE)
.size();
log.info("product total size is: " + total);
totalPage = (total - 1) / size + 1;
}
model.addAttribute("code", 0);
model.addAttribute("page", page);
model.addAttribute("size", size);
model.addAttribute("total", total);
model.addAttribute("totalPage", totalPage);
model.addAttribute("productList", productList);
}
catch (Throwable t) {
log.error(t.getMessage());
log.error("get product list error, page is: " + page + " , size is: " + size);
model.addAttribute("code", -1);
}
log.info("method getProductList() end...");
return "/playboy-invest-service/product/json/productListJson";
}
2.公司的图片API遇到问题
imgStorageUtil无法导入,暂时没有解决
明天计划的事情:继续写接口
遇到的问题:如上
收获:熟悉spring框架
评论