zheng-cms-web模块使用rpc订阅服务
This commit is contained in:
parent
4c2c37151c
commit
fa04138789
|
@ -17,7 +17,8 @@
|
|||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.zheng</groupId>
|
||||
<artifactId>zheng-cms-service</artifactId>
|
||||
<artifactId>zheng-cms-rpc-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.zheng.cms.web.controller;
|
||||
|
||||
import com.zheng.cms.service.UserService;
|
||||
import com.zheng.cms.rpc.api.UserService;
|
||||
import com.zheng.common.util.EhCacheUtil;
|
||||
import com.zheng.common.util.PropertiesFileUtil;
|
||||
import net.sf.ehcache.Cache;
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package com.zheng.cms.web.controller;
|
||||
|
||||
import com.zheng.cms.dao.model.User;
|
||||
import com.zheng.cms.service.impl.UserServiceImpl;
|
||||
import com.zheng.cms.rpc.api.UserService;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -31,11 +32,8 @@ public class HelloController extends BaseController {
|
|||
|
||||
private static Logger _log = LoggerFactory.getLogger(HelloController.class);
|
||||
|
||||
private UserServiceImpl userService;
|
||||
|
||||
public void setUserServiceImpl(UserServiceImpl userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@RequestMapping("/index")
|
||||
public String index() {
|
||||
|
@ -54,7 +52,7 @@ public class HelloController extends BaseController {
|
|||
@RequestMapping(value = "/view", method = RequestMethod.GET)
|
||||
public String viewCourse(@RequestParam("courseId") Integer courseId, Model model) {
|
||||
|
||||
User user = userService.getMapper().selectByPrimaryKey(courseId);
|
||||
User user = userService.selectByPrimaryKey(courseId);
|
||||
model.addAttribute(user);
|
||||
return "course_overview";
|
||||
}
|
||||
|
@ -63,7 +61,7 @@ public class HelloController extends BaseController {
|
|||
@RequestMapping("/view2/{courseId}")
|
||||
public String viewCourse2(@PathVariable("courseId") Integer courseId, Map<String, Object> map) {
|
||||
|
||||
User user = userService.getMapper().selectByPrimaryKey(courseId);
|
||||
User user = userService.selectByPrimaryKey(courseId);
|
||||
map.put("user", user);
|
||||
return "course_overview";
|
||||
}
|
||||
|
@ -73,7 +71,7 @@ public class HelloController extends BaseController {
|
|||
public String viewCourse3(HttpServletRequest request) {
|
||||
|
||||
Integer courseId = Integer.valueOf(request.getParameter("courseId"));
|
||||
User user = userService.getMapper().selectByPrimaryKey(courseId);
|
||||
User user = userService.selectByPrimaryKey(courseId);
|
||||
request.setAttribute("user", user);
|
||||
|
||||
return "course_overview";
|
||||
|
@ -132,12 +130,12 @@ public class HelloController extends BaseController {
|
|||
@RequestMapping(value = "/{courseId}", method = RequestMethod.GET)
|
||||
public @ResponseBody
|
||||
User getCourseInJson(@PathVariable Integer courseId) {
|
||||
return userService.getMapper().selectByPrimaryKey(courseId);
|
||||
return userService.selectByPrimaryKey(courseId);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/jsontype/{courseId}", method = RequestMethod.GET)
|
||||
public ResponseEntity<User> getCourseInJson2(@PathVariable Integer courseId) {
|
||||
User user = userService.getMapper().selectByPrimaryKey(courseId);
|
||||
User user = userService.selectByPrimaryKey(courseId);
|
||||
return new ResponseEntity<User>(user, HttpStatus.OK);
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ package com.zheng.cms.web.controller;
|
|||
|
||||
import com.zheng.cms.dao.model.User;
|
||||
import com.zheng.cms.dao.model.UserExample;
|
||||
import com.zheng.cms.service.UserService;
|
||||
import com.zheng.cms.rpc.api.UserService;
|
||||
import com.zheng.common.util.Paginator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -70,11 +70,11 @@ public class UserController extends BaseController {
|
|||
userExample.setLimit(rows);
|
||||
userExample.setDistinct(false);
|
||||
userExample.setOrderByClause(" user_id asc ");
|
||||
List<User> users = userService.getMapper().selectByExample(userExample);
|
||||
List<User> users = userService.selectByExample(userExample);
|
||||
model.addAttribute("users", users);
|
||||
|
||||
// 创建分页对象
|
||||
long total = userService.getMapper().countByExample(userExample);
|
||||
long total = userService.countByExample(userExample);
|
||||
Paginator paginator = new Paginator();
|
||||
paginator.setTotal(total);
|
||||
paginator.setPage(page);
|
||||
|
@ -112,7 +112,7 @@ public class UserController extends BaseController {
|
|||
}
|
||||
user.setCtime(System.currentTimeMillis());
|
||||
|
||||
userService.getMapper().insertSelective(user);
|
||||
userService.insertSelective(user);
|
||||
|
||||
_log.info("新增记录id为:{}", user.getUserId());
|
||||
|
||||
|
@ -126,7 +126,7 @@ public class UserController extends BaseController {
|
|||
*/
|
||||
@RequestMapping(value = "/delete/{id}",method = RequestMethod.GET)
|
||||
public String delete(@PathVariable("id") int id) {
|
||||
userService.getMapper().deleteByPrimaryKey(id);
|
||||
userService.deleteByPrimaryKey(id);
|
||||
return "redirect:/user/list";
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ public class UserController extends BaseController {
|
|||
*/
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
|
||||
public String update(@PathVariable("id") int id, Model model) {
|
||||
model.addAttribute("user", userService.getMapper().selectByPrimaryKey(id));
|
||||
model.addAttribute("user", userService.selectByPrimaryKey(id));
|
||||
return "/user/update";
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ public class UserController extends BaseController {
|
|||
model.addAttribute("errors", binding.getAllErrors());
|
||||
return "user/update/" + id;
|
||||
}
|
||||
userService.getMapper().updateByPrimaryKeySelective(user);
|
||||
userService.updateByPrimaryKeySelective(user);
|
||||
return "redirect:/user/list";
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,7 @@ public class UserController extends BaseController {
|
|||
@ResponseBody
|
||||
@RequestMapping(value = "/ajax/{id}", method = RequestMethod.GET)
|
||||
public Object ajax(@PathVariable int id) {
|
||||
return userService.getMapper().selectByPrimaryKey(id);
|
||||
return userService.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
}
|
|
@ -3,7 +3,7 @@ package com.zheng.cms.web.controller.manage;
|
|||
import com.zheng.cms.web.controller.BaseController;
|
||||
import com.zheng.cms.dao.model.CmsArticle;
|
||||
import com.zheng.cms.dao.model.CmsArticleExample;
|
||||
import com.zheng.cms.service.CmsArticleService;
|
||||
import com.zheng.cms.rpc.api.CmsArticleService;
|
||||
import com.zheng.common.util.Paginator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -52,10 +52,10 @@ public class CmsArticleController extends BaseController {
|
|||
cmsArticleExample.setOffset((page - 1) * rows);
|
||||
cmsArticleExample.setLimit(rows);
|
||||
cmsArticleExample.setOrderByClause(desc ? "orders desc" : "orders asc");
|
||||
List<CmsArticle> articles = cmsArticleService.getMapper().selectByExample(cmsArticleExample);
|
||||
List<CmsArticle> articles = cmsArticleService.selectByExample(cmsArticleExample);
|
||||
|
||||
// 分页对象
|
||||
long total = cmsArticleService.getMapper().countByExample(cmsArticleExample);
|
||||
long total = cmsArticleService.countByExample(cmsArticleExample);
|
||||
Paginator paginator = new Paginator(total, page, rows, request);
|
||||
|
||||
model.addAttribute("articles", articles);
|
||||
|
@ -83,7 +83,7 @@ public class CmsArticleController extends BaseController {
|
|||
long time = System.currentTimeMillis();
|
||||
cmsArticle.setCtime(time);
|
||||
cmsArticle.setOrders(time);
|
||||
int count = cmsArticleService.getMapper().insertSelective(cmsArticle);
|
||||
int count = cmsArticleService.insertSelective(cmsArticle);
|
||||
model.addAttribute("count", count);
|
||||
_log.info("新增记录id为:{}", cmsArticle.getArticleId());
|
||||
return "redirect:/manage/article/list";
|
||||
|
@ -110,7 +110,7 @@ public class CmsArticleController extends BaseController {
|
|||
*/
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
|
||||
public String update(@PathVariable("id") int id, Model model) {
|
||||
CmsArticle article = cmsArticleService.getMapper().selectByPrimaryKey(id);
|
||||
CmsArticle article = cmsArticleService.selectByPrimaryKey(id);
|
||||
model.addAttribute("article", article);
|
||||
return "/manage/article/update";
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ public class CmsArticleController extends BaseController {
|
|||
*/
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
public String update(@PathVariable("id") int id, CmsArticle cmsArticle, Model model) {
|
||||
int count = cmsArticleService.getMapper().updateByPrimaryKeySelective(cmsArticle);
|
||||
int count = cmsArticleService.updateByPrimaryKeySelective(cmsArticle);
|
||||
model.addAttribute("count", count);
|
||||
model.addAttribute("id", id);
|
||||
return "redirect:/manage/article/list";
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.zheng.cms.web.controller.manage;
|
|||
import com.zheng.cms.web.controller.BaseController;
|
||||
import com.zheng.cms.dao.model.CmsCategory;
|
||||
import com.zheng.cms.dao.model.CmsCategoryExample;
|
||||
import com.zheng.cms.service.CmsCategoryService;
|
||||
import com.zheng.cms.rpc.api.CmsCategoryService;
|
||||
import com.zheng.common.util.Paginator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -52,10 +52,10 @@ public class CmsCategoryController extends BaseController {
|
|||
cmsCategoryExample.setOffset((page - 1) * rows);
|
||||
cmsCategoryExample.setLimit(rows);
|
||||
cmsCategoryExample.setOrderByClause(desc ? "orders desc" : "orders asc");
|
||||
List<CmsCategory> categorys = cmsCategoryService.getMapper().selectByExample(cmsCategoryExample);
|
||||
List<CmsCategory> categorys = cmsCategoryService.selectByExample(cmsCategoryExample);
|
||||
|
||||
// 分页对象
|
||||
long total = cmsCategoryService.getMapper().countByExample(cmsCategoryExample);
|
||||
long total = cmsCategoryService.countByExample(cmsCategoryExample);
|
||||
Paginator paginator = new Paginator(total, page, rows, request);
|
||||
|
||||
model.addAttribute("categorys", categorys);
|
||||
|
@ -83,7 +83,7 @@ public class CmsCategoryController extends BaseController {
|
|||
long time = System.currentTimeMillis();
|
||||
cmsCategory.setCtime(time);
|
||||
cmsCategory.setOrders(time);
|
||||
int count = cmsCategoryService.getMapper().insertSelective(cmsCategory);
|
||||
int count = cmsCategoryService.insertSelective(cmsCategory);
|
||||
model.addAttribute("count", count);
|
||||
_log.info("新增记录id为:{}", cmsCategory.getCategoryId());
|
||||
return "redirect:/manage/category/list";
|
||||
|
@ -110,7 +110,7 @@ public class CmsCategoryController extends BaseController {
|
|||
*/
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
|
||||
public String update(@PathVariable("id") int id, Model model) {
|
||||
CmsCategory category = cmsCategoryService.getMapper().selectByPrimaryKey(id);
|
||||
CmsCategory category = cmsCategoryService.selectByPrimaryKey(id);
|
||||
model.addAttribute("category", category);
|
||||
return "/manage/category/update";
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ public class CmsCategoryController extends BaseController {
|
|||
*/
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
public String update(@PathVariable("id") int id, CmsCategory cmsCategory, Model model) {
|
||||
int count = cmsCategoryService.getMapper().updateByPrimaryKeySelective(cmsCategory);
|
||||
int count = cmsCategoryService.updateByPrimaryKeySelective(cmsCategory);
|
||||
model.addAttribute("count", count);
|
||||
model.addAttribute("id", id);
|
||||
return "redirect:/manage/category/list";
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.zheng.cms.web.controller.manage;
|
|||
import com.zheng.cms.web.controller.BaseController;
|
||||
import com.zheng.cms.dao.model.CmsComment;
|
||||
import com.zheng.cms.dao.model.CmsCommentExample;
|
||||
import com.zheng.cms.service.CmsCommentService;
|
||||
import com.zheng.cms.rpc.api.CmsCommentService;
|
||||
import com.zheng.common.util.Paginator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -52,10 +52,10 @@ public class CmsCommentController extends BaseController {
|
|||
cmsCommentExample.setOffset((page - 1) * rows);
|
||||
cmsCommentExample.setLimit(rows);
|
||||
cmsCommentExample.setOrderByClause(desc ? "comment_id desc" : "comment_id asc");
|
||||
List<CmsComment> comments = cmsCommentService.getMapper().selectByExample(cmsCommentExample);
|
||||
List<CmsComment> comments = cmsCommentService.selectByExample(cmsCommentExample);
|
||||
|
||||
// 分页对象
|
||||
long total = cmsCommentService.getMapper().countByExample(cmsCommentExample);
|
||||
long total = cmsCommentService.countByExample(cmsCommentExample);
|
||||
Paginator paginator = new Paginator(total, page, rows, request);
|
||||
|
||||
model.addAttribute("comments", comments);
|
||||
|
@ -81,7 +81,7 @@ public class CmsCommentController extends BaseController {
|
|||
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||
public String add(CmsComment cmsComment, Model model) {
|
||||
cmsComment.setCtime(System.currentTimeMillis());
|
||||
int count = cmsCommentService.getMapper().insertSelective(cmsComment);
|
||||
int count = cmsCommentService.insertSelective(cmsComment);
|
||||
model.addAttribute("count", count);
|
||||
_log.info("新增记录id为:{}", cmsComment.getArticleId());
|
||||
return "redirect:/manage/comment/list";
|
||||
|
@ -108,7 +108,7 @@ public class CmsCommentController extends BaseController {
|
|||
*/
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
|
||||
public String update(@PathVariable("id") int id, Model model) {
|
||||
CmsComment comment = cmsCommentService.getMapper().selectByPrimaryKey(id);
|
||||
CmsComment comment = cmsCommentService.selectByPrimaryKey(id);
|
||||
model.addAttribute("comment", comment);
|
||||
return "/manage/comment/update";
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ public class CmsCommentController extends BaseController {
|
|||
*/
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
public String update(@PathVariable("id") int id, CmsComment cmsComment, Model model) {
|
||||
int count = cmsCommentService.getMapper().updateByPrimaryKeySelective(cmsComment);
|
||||
int count = cmsCommentService.updateByPrimaryKeySelective(cmsComment);
|
||||
model.addAttribute("count", count);
|
||||
model.addAttribute("id", id);
|
||||
return "redirect:/manage/comment/list";
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.zheng.cms.web.controller.manage;
|
|||
import com.zheng.cms.web.controller.BaseController;
|
||||
import com.zheng.cms.dao.model.CmsTag;
|
||||
import com.zheng.cms.dao.model.CmsTagExample;
|
||||
import com.zheng.cms.service.CmsTagService;
|
||||
import com.zheng.cms.rpc.api.CmsTagService;
|
||||
import com.zheng.common.util.Paginator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -52,10 +52,10 @@ public class CmsTagController extends BaseController {
|
|||
cmsTagExample.setOffset((page - 1) * rows);
|
||||
cmsTagExample.setLimit(rows);
|
||||
cmsTagExample.setOrderByClause(desc ? "orders desc" : "orders asc");
|
||||
List<CmsTag> tags = cmsTagService.getMapper().selectByExample(cmsTagExample);
|
||||
List<CmsTag> tags = cmsTagService.selectByExample(cmsTagExample);
|
||||
|
||||
// 分页对象
|
||||
long total = cmsTagService.getMapper().countByExample(cmsTagExample);
|
||||
long total = cmsTagService.countByExample(cmsTagExample);
|
||||
Paginator paginator = new Paginator(total, page, rows, request);
|
||||
|
||||
model.addAttribute("tags", tags);
|
||||
|
@ -83,7 +83,7 @@ public class CmsTagController extends BaseController {
|
|||
long time = System.currentTimeMillis();
|
||||
cmsTag.setCtime(time);
|
||||
cmsTag.setOrders(time);
|
||||
int count = cmsTagService.getMapper().insertSelective(cmsTag);
|
||||
int count = cmsTagService.insertSelective(cmsTag);
|
||||
model.addAttribute("count", count);
|
||||
_log.info("新增记录id为:{}", cmsTag.getTagId());
|
||||
return "redirect:/manage/tag/list";
|
||||
|
@ -110,7 +110,7 @@ public class CmsTagController extends BaseController {
|
|||
*/
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
|
||||
public String update(@PathVariable("id") int id, Model model) {
|
||||
CmsTag tag = cmsTagService.getMapper().selectByPrimaryKey(id);
|
||||
CmsTag tag = cmsTagService.selectByPrimaryKey(id);
|
||||
model.addAttribute("tag", tag);
|
||||
return "/manage/tag/update";
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ public class CmsTagController extends BaseController {
|
|||
*/
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
public String update(@PathVariable("id") int id, CmsTag cmsTag, Model model) {
|
||||
int count = cmsTagService.getMapper().updateByPrimaryKeySelective(cmsTag);
|
||||
int count = cmsTagService.updateByPrimaryKeySelective(cmsTag);
|
||||
model.addAttribute("count", count);
|
||||
model.addAttribute("id", id);
|
||||
return "redirect:/manage/tag/list";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.zheng.cms.web.jms;
|
||||
|
||||
import com.zheng.cms.dao.model.User;
|
||||
import com.zheng.cms.service.UserService;
|
||||
import com.zheng.cms.rpc.api.UserService;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -43,7 +43,7 @@ public class defaultQueueMessageListener implements MessageListener {
|
|||
if (user.getUsername().equals("1000")) {
|
||||
_log.info("消费结束时间:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis())));
|
||||
}
|
||||
userService.getMapper().insertSelective(user);
|
||||
userService.insertSelective(user);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://code.alibabatech.com/schema/dubbo
|
||||
http://code.alibabatech.com/schema/dubbo/dubbo.xsd ">
|
||||
|
||||
<dubbo:application name="zheng-upms-server"/>
|
||||
|
||||
<dubbo:registry protocol="zookeeper" address="127.0.0.1:2181"/>
|
||||
|
||||
<!-- 订阅服务 -->
|
||||
<dubbo:reference id="cmsArticleService" interface="com.zheng.cms.rpc.api.CmsArticleService" />
|
||||
|
||||
<dubbo:reference id="cmsCategoryService" interface="com.zheng.cms.rpc.api.CmsCategoryService" />
|
||||
|
||||
<dubbo:reference id="cmsCommentService" interface="com.zheng.cms.rpc.api.CmsCommentService" />
|
||||
|
||||
<dubbo:reference id="cmsTagService" interface="com.zheng.cms.rpc.api.CmsTagService" />
|
||||
|
||||
<dubbo:reference id="userService" interface="com.zheng.cms.rpc.api.UserService" />
|
||||
|
||||
</beans>
|
Loading…
Reference in New Issue