发表于: 2018-09-10 00:02:48
1 406
今天完成的事情:
以下是9号的日报,提交过了0点了。今天的日报在下9号日报下面:
1.表设计
2.接口测试
1.表设计
惯性思维,不需要中间表,直接去掉了。
2.写接口,测试
已写接口:查询客户案例-新闻案例-banner图列表、查询所有产品、产品的增删改查,分类的增删改查
/**
* @param: [request, response, model, page, size, status]
* @return: java.lang.String
* @auther: Zhang Qiang
* @date: 2018/9/9 18:43
* @info: 查询所有产品
*
*/
@RequestMapping(value = "/a/product/list",method = RequestMethod.GET)
public String getAllProduct(HttpServletRequest request,
HttpServletResponse response, ModelMap model, Integer page, Integer size, Integer status){
log.info("page:" + page + ", size:" + size);
if (page == null) page = 1;
if (size == null) size = 6;
int start = (page - 1) * size;
if (start < 0) start = 0;
if (status == null || status >1) status = 1;
Map<String, Object> params = null;
List<Long> ids = null;
List<Product> productList = null;
List<Long> count = null;
try {
ids = productService.getProductIdsByStatus(status,start,size);
productList = productService.getObjectsByIds(ids);
count = productService.getIdsByDynamicCondition(Product.class, params, 0, Integer.MAX_VALUE);
model.addAttribute("code", 0);
model.addAttribute("page", page);
model.addAttribute("size", size);
model.addAttribute("total", count.size());
model.addAttribute("atlasList", productList);
message = "查询成功";
model.addAttribute("message",message);
log.info("productList is: " + productList.size());
}catch (Throwable t) {
t.printStackTrace();
log.error(t.getMessage());
log.error("get productService error ");
model.addAttribute("code", -100000);
model.addAttribute("message", t.getMessage());
}
return "/atlascopco-service/product/json/productListJson";
}
/**
* @param: [request, response, model, page, size, type, status]
* @return: java.lang.String
* @auther: Zhang Qiang
* @date: 2018/9/9 21:16
* @info: 客户案例、新闻案例、banner图统一接口,返回ListJson,默认每页5条数据
*
*/
@RequestMapping(value = "/a/example/list ", method = RequestMethod.GET)
public String getExampleList(HttpServletRequest request,
HttpServletResponse response, ModelMap model, Integer page,
Integer size,Integer type, Integer status) throws Exception {
if (page == null) page = 1;
if (size == null) size = 5;
int start = (page - 1) * size;
if (start < 0) start = 0;
if (status == null || status >1) status = 1;
if (type == null || type > 3) {
model.addAttribute("code", -10000);
model.addAttribute("message", "type为空或传参错误");
return "common/fail";
}
log.info("pageList : page= " + start + " , size=" + size);
List<Long> ids = null;
List<Example> exampleList = null;
try {
//List<Long> ids = exampleService.getExampleIdsByTypeAndStatus(type,status,start,size);
Map params = new HashMap();
params.put("type",type);
params.put("status",status);
// params.put("@query", "id,create_at,update_at,create_by,update_by,title,type,url,img_url,intro,content,status");
params.put("@query", "id");
params.put("@table", "example");
params.put("@order","status desc, update_at desc");
log.info(SQLUtil.convert2Sql(params, 0, Integer.MAX_VALUE));
ids = exampleService.getIdsByDynamicCondition(Example.class,params,start,size);
log.info("get countExampleIdsByType size is " + ids.size());
exampleList = exampleService.getObjectsByIds(ids);
log.info("get example data is " + exampleList.size());
Integer total = exampleService. countExampleIdsByType(type);
log.info("get example count is " + total);
model.addAttribute("code", 0);
model.addAttribute("page", page);
model.addAttribute("size", size);
model.addAttribute("total", total);
model.addAttribute("exampleList", exampleList);
model.addAttribute("message", message);
} catch (Throwable t) {
t.printStackTrace();
message = t.getMessage();
log.error(t.getMessage());
log.error("get example list error,page is " + start + " , size "
+ size);
// for test
model.addAttribute("code", -100000);
model.addAttribute("message", message);
return "common/fail";
}
return "/atlascopco-service/example/json/exampleListJson";
}
以上例举,明天继续测试
明天计划的事情:
1.空压机二期方案评审
2.空压机二期接口文档
3.接口编写
遇到的问题:
1.测试的时候出现无法转换为BigInteger
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.math.BigInteger
??????
哪来的bigInteger????
Map params = new HashMap();
params.put("type",type);
params.put("status",status);
// params.put("@query", "id,create_at,update_at,create_by,update_by,title,type,url,img_url,intro,content,status");
params.put("@query", "id");
params.put("@table", "example");
params.put("@order","status desc, update_at desc");
log.info(SQLUtil.convert2Sql(params, 0, Integer.MAX_VALUE));
ids = exampleService.getIdsByDynamicCondition(Example.class,params,start,size);
原来这个地方只支持查一个id,找了半天发现是getIdsByDynamicCondition,醉了
2.公司框架没有getObjectsById只有getObjectsByIds,通过ids数组查询,自动生成了又太麻烦;
这种通过一个分类id查询所有产品就会多几个操作,还好。
以下为10号日报:
今天完成的事情:
1、重写方案,方案评审
2、空压机官网二期,禅道拆分
3、接口文档(未完)
4、接口测试
接口:
获取所有分类和分类下的产品
/**
*
* @param:
* @return:
* @auther: Zhang Qiang
* @date: 2018/9/10 16:03
* @info: 搜索所有分类和产品
*
*/
@ResponseBody
@RequestMapping(value = "/a/sort/product/list")
public ModelMap getSortProduct(HttpServletRequest request, HttpServletResponse response, ModelMap model,Integer page, Integer size){ ……
获取单个分类下的信息:
/**
* @param: [request, response, model, sortId, page, size]
* @return: java.lang.String
* @auther: Zhang Qiang
* @date: 2018/9/10 20:00
* @info: 获取分类下所有产品 sortId 分类id
*
*/
@RequestMapping(value = "/a/sort/{sortId}/products",method = RequestMethod.GET)
public String getProductBySortId(HttpServletRequest request, HttpServletResponse response, ModelMap model,@PathVariable(value = "sortId") Integer sortId ,Integer page, Integer size){
这里主要测试添加的字段,之前设计的表都废弃了,因为绍博师兄说数据量少,没必要设置多余的表。能在一张表操作就不做其他多余的设计了,只是这样还是要在表里面添加字段。
因为是框架生成的,不知道添加了字段会不会出现意料之外的错误。所以今天一直在测试。
以上
明天计划的事情:
1.接口文档对接
2.按照禅道开发接口
遇到的问题:
1.在使用动态创建语句的时候报了空指针错误:
但是这里并没有问题;
后来发现创建Map的时候出了问题,创建的时候没有初始化内存空间,也就是这里不能设为空值:
问题出在map虽然初始化了,但是成员变量默认初始化为null,并没有分配内存,此时对map进行put操作,势必会报空指针异常。
2.jsp页面
由于返回的时候需要返回 分类Object+产品list。这里就直接返回Map类型,数据格式是Map<Object,List>,但是公司代码生成的jsp满足不了要求,写了一个测试发现仍然不行,因为要循环出map和里面的list:
<json:object escapeXml="false">
<json:property name="code" value="${code}"></json:property>
<%--<json:property name="message">--%>
<%--<spring:message code="${code}" />--%>
<%--</json:property>--%>
<json:property name="page" value="${page}"></json:property>
<json:property name="size" value="${size}"></json:property>
<json:property name="total" value="${total}"></json:property>
<json:array name="data">
<c:forEach items="${sortProductMap}" var="atlascopco">
<json:object>
<json:property name="id" value="${atlascopco.key.id}"></json:property>
<json:property name="type" value="${atlascopco.key.type}"></json:property>
<json:property name="title" value="${atlascopco.key.title}"></json:property>
<json:property name="author" value="${atlascopco.key.author}"></json:property>
<json:property name="url" value="${atlascopco.key.url}"></json:property>
<json:property name="img" value="${atlascopco.key.img}"></json:property>
<json:property name="introduce" value="${atlascopco.key.introduce}"></json:property>
<json:property name="content" value="${atlascopco.key.content}"></json:property>
<json:property name="status" value="${atlascopco.key.status}"></json:property>
<json:property name="creater" value="${atlascopco.key.creater}"></json:property>
<json:property name="createAt" value="${atlascopco.key.createAt}"></json:property>
<json:property name="createBy" value="${atlascopco.key.createBy}"></json:property>
<json:property name="updateAt" value="${atlascopco.key.updateAt}"></json:property>
<json:property name="updateBy" value="${atlascopco.key.updateBy}"></json:property>
</json:object>
<c:forEach items="${atlascopco.value}" var="product" >
<json:object>
<json:property name="id" value="${product.id}"></json:property>
<json:property name="type" value="${product.type}"></json:property>
<json:property name="title" value="${product.title}"></json:property>
<json:property name="author" value="${product.author}"></json:property>
<json:property name="url" value="${product.url}"></json:property>
<json:property name="img" value="${product.img}"></json:property>
<json:property name="introduce" value="${product.introduce}"></json:property>
<json:property name="content" value="${product.content}"></json:property>
<json:property name="status" value="${product.status}"></json:property>
<json:property name="creater" value="${product.creater}"></json:property>
<json:property name="createAt" value="${product.createAt}"></json:property>
<json:property name="createBy" value="${product.createBy}"></json:property>
<json:property name="updateAt" value="${product.updateAt}"></json:property>
<json:property name="updateBy" value="${product.updateBy}"></json:property>
</json:object>
</c:forEach>
</c:forEach>
</json:array>
</json:object>
这里嵌套for循环,试了几种方式,要么是后面的list不输出,要么是格式不正确,json-taglib标签在这种情况下还是不怎么好用。
但是直接返回map会打破格式,就是无法携带code、page这些信息:
最后干脆直接返回model,然后@ResponseBody,返回上面的数据;
over;
评论