发表于: 2017-08-03 12:36:09
1 928
今天完成的事情:
后台Article新增接口、删除接口、更新接口、更新上下线接口
明天计划的事情:
测试接口、部署开发环境、写前台Article接口
收获:
java中null 和 “ ”区别
null代表声明了一个空对象,不是一个字符串,对空对象只能做=和==操作,其余都不可以
“”代表声明了一个对象实例,这个对象实例的值是一个长度为0的空字符串
Spring s = null;是定义了一个句柄或者一个引用,但是这个引用未指向任何内存空间
request.getCookie()获取当前路径以及父路径的cookie值
String s = “”这个引用已经指向一块是空字符串的内存空间,所以可以对他操作,而不用担心什么
修改Article上线下线状态接口:
estMapping(value = "/a/u/article/{id}", method = RequestMethod.PUT)
public String updateStatus(HttpServletRequest request, HttpServletResponse response,
@PathVariable Long id,
Integer status, ModelMap model) throws Exception {
if (id == null) {
model.addAttribute("code", -1000);
log.error("put article status error and id is null");
return "common/fail";
}
Article article = articleService.getObjectById(id);
log.info("update article id :" + id + "status : " + status);
Long adminId = null;
try {
adminId = CookieUtil.getAdminId(request);
log.info("获取管理员身份成功! adminId:" + adminId);
} catch (Throwable t) {
log.error("获取管理员身份失败!");
t.printStackTrace();
log.error(t.getMessage());
model.addAttribute("code", -1000);
return "common/fail";
}
article.setUpdateBy(adminId);
article.setStatus(status);
try {
articleService.update(article);
log.info("article状态更新成功!article" + id);
model.addAttribute("code", 0);
} catch (Throwable t) {
log.error("更新Article状态失败! article :" + id);
t.printStackTrace();
log.error(t.getMessage());
model.addAttribute("code", -1000);
return "common/fail";
}
return"common/success";
遇到的问题:
上传图片的接口,还没看明白怎么写
评论