删除旧代码

This commit is contained in:
shuzheng 2016-12-01 13:45:25 +08:00
parent 1d9609c805
commit a4b17b84e4
18 changed files with 0 additions and 1456 deletions

View File

@ -1,47 +0,0 @@
package com.zheng.cms.jms;
import com.zheng.cms.dao.model.User;
import com.zheng.cms.service.UserService;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
/**
* MQ消费者
* Created by ZhangShuzheng on 2016/11/24.
*/
public class defaultQueueMessageListener implements MessageListener {
private static Logger _log = LoggerFactory.getLogger(defaultQueueMessageListener.class);
@Autowired
ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Autowired
UserService userService;
public void onMessage(final Message message) {
// 使用线程池多线程处理
threadPoolTaskExecutor.execute(new Runnable() {
public void run() {
TextMessage textMessage = (TextMessage) message;
try {
String text = textMessage.getText();
JSONObject json = JSONObject.fromObject(text);
User user = (User) JSONObject.toBean(json, User.class);
userService.getMapper().insertSelective(user);
_log.info("zheng-cms-mq接收到{}", text);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}

View File

@ -1,36 +0,0 @@
package com.zheng.cms.Interceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 后台过滤器
* Created by ZhangShuzheng on 2016/10/17.
*/
public class ManageInterceptor extends HandlerInterceptorAdapter {
private static Logger _log = LoggerFactory.getLogger(ManageInterceptor.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
_log.info("ManageInterceptor==>preHandle");
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}

View File

@ -1,63 +0,0 @@
package com.zheng.cms.controller;
import com.zheng.cms.dao.model.User;
import com.zheng.common.util.JmsUtil;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.jms.Destination;
/**
* 消息队列controller
* @author shuzheng
* @date 2016年11月24日
*/
@Controller
@RequestMapping("/activemq")
public class ActiveMQController extends BaseController {
private static Logger _log = LoggerFactory.getLogger(ActiveMQController.class);
@Autowired
JmsTemplate jmsQueueTemplate;
@Autowired
Destination defaultQueueDestination;
@RequestMapping("/send")
@ResponseBody
public Object send() {
long start = System.currentTimeMillis();
User user = null;
for (int i = 1; i <= 1000; i ++) {
user = new User();
user.setUsername("用户" + i);
user.setPassword("123456");
user.setNickname("昵称");
user.setSex(1);
user.setCtime(System.currentTimeMillis());
user.setContent("用户描述");
// jmsQueueTemplate.convertAndSend(defaultQueueDestination, user);
JmsUtil.sendMessage(jmsQueueTemplate, defaultQueueDestination, JSONObject.fromObject(user).toString());
}
_log.info("发送消息消耗时间" + (System.currentTimeMillis() - start));
return "success";
}
public static void main(String[] args) {
User user = new User();
user.setUsername("用户");
user.setPassword("123456");
user.setNickname("昵称");
user.setSex(1);
user.setCtime(System.currentTimeMillis());
user.setContent("用户描述");
System.out.println(JSONObject.fromObject(user).toString());
}
}

View File

@ -1,15 +0,0 @@
package com.zheng.cms.controller;
/**
* 控制器基类
* @author shuzheng
* @date 2016年7月7日 上午10:08:47
*/
public class BaseController {
public static final String RESULT = "result";
public static final String DATA = "data";
public static final String SUCCESS = "success";
public static final String FAILED = "failed";
}

View File

@ -1,102 +0,0 @@
package com.zheng.cms.controller;
import com.zheng.cms.service.UserService;
import com.zheng.common.util.EhCacheUtil;
import com.zheng.common.util.PropertiesFileUtil;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
/**
* 缓存controller
* @author shuzheng
* @date 2016年10月15日
*/
@Controller
@RequestMapping("/ehcache")
public class EhCacheController extends BaseController {
private static Logger _log = LoggerFactory.getLogger(EhCacheController.class);
private final static String EHCACHE_NAME = PropertiesFileUtil.getInstance().get("ehcache");
@Autowired
private UserService userService;
@RequestMapping("/test")
@ResponseBody
public Object test(HttpServletRequest request) {
return System.getProperty("java.io.tmpdir");
}
/**
* 新增缓存记录
* @param request
* @return
*/
@RequestMapping("/add")
@ResponseBody
public Object add(HttpServletRequest request) {
String key = request.getParameter("key");
String value = request.getParameter("value");
EhCacheUtil.put(EHCACHE_NAME, key, value);
return "success";
}
/**
* 删除缓存记录
* @param request
* @return
*/
@RequestMapping("/remove")
@ResponseBody
public Object remove(HttpServletRequest request) {
String key = request.getParameter("key");
EhCacheUtil.remove(EHCACHE_NAME, key);
return "success";
}
/**
* 获取缓存记录
* @param request
* @return
*/
@RequestMapping("/get")
@ResponseBody
public Object get(HttpServletRequest request) {
String key = request.getParameter("key");
Object object = EhCacheUtil.get(EHCACHE_NAME, key);
if (null == object) {
_log.debug("【Ehcache】没有找到key={}的记录!", key);
return "";
}
return object;
}
public static void main(String[] args) {
// EhCache调用
// Create a cache manager
final CacheManager cacheManager = CacheManager.getInstance();
// create the cache called "hello-world"
final Cache cache = cacheManager.getCache("ehcache_common");
// create a key to map the data to
final String key = "key";
// Create a data element
final Element element = new Element(key, "value");
// Put the element into the data store
cache.put(element);
// Retrieve the data element
final Element cacheElement = cache.get(key);
// Print the value
System.out.println(cacheElement.getObjectValue());
}
}

View File

@ -1,143 +0,0 @@
package com.zheng.cms.controller;
import com.zheng.cms.dao.model.User;
import com.zheng.cms.service.impl.UserServiceImpl;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
/**
* 示例controller
* @author shuzheng
* @date 2016年7月6日 下午6:16:00
*/
@Controller
@RequestMapping("/hello")
public class HelloController extends BaseController {
private static Logger _log = LoggerFactory.getLogger(HelloController.class);
private UserServiceImpl userService;
public void setUserServiceImpl(UserServiceImpl userService) {
this.userService = userService;
}
@RequestMapping("/index")
public String index() {
// 视图渲染/WEB-INF/jsp/hello/world.jsp
return "/hello/world";
}
// 方法级别的RequestMapping 限制并缩小了URL路径匹配同类级别的标签协同工作最终确定拦截到的URL由那个方法处理
@RequestMapping("/world")
public String world() {
// 视图渲染/WEB-INF/jsp/hello/world.jsp
return "/hello/world";
}
// 本方法将处理 /hello/view?courseId=123 形式的URL
@RequestMapping(value = "/view", method = RequestMethod.GET)
public String viewCourse(@RequestParam("courseId") Integer courseId, Model model) {
User user = userService.getMapper().selectByPrimaryKey(courseId);
model.addAttribute(user);
return "course_overview";
}
// 本方法将处理 /hello/view2/123 形式的URL
@RequestMapping("/view2/{courseId}")
public String viewCourse2(@PathVariable("courseId") Integer courseId, Map<String, Object> map) {
User user = userService.getMapper().selectByPrimaryKey(courseId);
map.put("user", user);
return "course_overview";
}
// 本方法将处理 /hello/view3?courseId=123 形式的URL
@RequestMapping("/view3")
public String viewCourse3(HttpServletRequest request) {
Integer courseId = Integer.valueOf(request.getParameter("courseId"));
User user = userService.getMapper().selectByPrimaryKey(courseId);
request.setAttribute("user", user);
return "course_overview";
}
@RequestMapping(value = "/admin", method = RequestMethod.GET, params = "add")
public String createCourse() {
return "course_admin/edit";
}
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String doSave(@ModelAttribute User user) {
_log.debug("Info of Course:");
_log.debug(ReflectionToStringBuilder.toString(user));
// 在此进行业务操作比如数据库持久化
user.setUserId(123);
return "redirect:view2/" + user.getUserId();
}
@RequestMapping(value = "/upload", method = RequestMethod.GET)
public String showUploadPage(@RequestParam(value = "multi", required = false) Boolean multi) {
if (multi != null && multi) {
return "course_admin/multifile";
}
return "course_admin/file";
}
@RequestMapping(value = "/doUpload", method = RequestMethod.POST)
public String doUploadFile(@RequestParam("file") MultipartFile file) throws IOException {
if (!file.isEmpty()) {
FileUtils.copyInputStreamToFile(file.getInputStream(), new File("c:\\temp\\imooc\\", System.currentTimeMillis() + file.getOriginalFilename()));
}
return "success";
}
@RequestMapping(value = "/doUpload2", method = RequestMethod.POST)
public String doUploadFile2(MultipartHttpServletRequest multiRequest) throws IOException {
Iterator<String> filesNames = multiRequest.getFileNames();
while (filesNames.hasNext()) {
String fileName = filesNames.next();
MultipartFile file = multiRequest.getFile(fileName);
if (!file.isEmpty()) {
FileUtils.copyInputStreamToFile(file.getInputStream(), new File("c:\\temp\\imooc\\", System.currentTimeMillis() + file.getOriginalFilename()));
}
}
return "success";
}
@RequestMapping(value = "/{courseId}", method = RequestMethod.GET)
public @ResponseBody
User getCourseInJson(@PathVariable Integer courseId) {
return userService.getMapper().selectByPrimaryKey(courseId);
}
@RequestMapping(value = "/jsontype/{courseId}", method = RequestMethod.GET)
public ResponseEntity<User> getCourseInJson2(@PathVariable Integer courseId) {
User user = userService.getMapper().selectByPrimaryKey(courseId);
return new ResponseEntity<User>(user, HttpStatus.OK);
}
}

View File

@ -1,29 +0,0 @@
package com.zheng.cms.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 后台controller
* @author shuzheng
* @date 2016年10月18日
*/
@Controller
@RequestMapping("/manage")
public class ManageController extends BaseController {
private static Logger _log = LoggerFactory.getLogger(ManageController.class);
@RequestMapping(value = {"", "/index"})
public String index() {
return "/manage/index";
}
@RequestMapping("/login")
public String login() {
return "/manage/login";
}
}

View File

@ -1,82 +0,0 @@
package com.zheng.cms.controller;
import com.zheng.common.util.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
/**
* 缓存controller
*
* @author shuzheng
* @date 2016年11月26日
*/
@Controller
@RequestMapping("/redis")
public class RedisController extends BaseController {
private static Logger _log = LoggerFactory.getLogger(RedisController.class);
@RequestMapping("/test")
@ResponseBody
public Object test(HttpServletRequest request) {
long time = System.currentTimeMillis();
for (int i = 1; i <= 10000; i ++) {
RedisUtil.set("key" + i, "value" + i, i * 5);
}
return System.currentTimeMillis() - time;
}
/**
* 新增缓存记录
*
* @param request
* @return
*/
@RequestMapping("/add")
@ResponseBody
public Object add(HttpServletRequest request) {
String key = request.getParameter("key");
String value = request.getParameter("value");
String time = request.getParameter("time");
RedisUtil.set(key, value, Integer.parseInt(time));
return "success";
}
/**
* 删除缓存记录
*
* @param request
* @return
*/
@RequestMapping("/remove")
@ResponseBody
public Object remove(HttpServletRequest request) {
String key = request.getParameter("key");
RedisUtil.remove(key);
return "success";
}
/**
* 获取缓存记录
*
* @param request
* @return
*/
@RequestMapping("/get")
@ResponseBody
public Object get(HttpServletRequest request) {
String key = request.getParameter("key");
String value = RedisUtil.get(key);
if (null == value) {
_log.debug("【redis】没有找到key={}的记录!", key);
return "";
}
return value;
}
}

View File

@ -1,213 +0,0 @@
package com.zheng.cms.controller;
import com.zheng.cms.dao.model.User;
import com.zheng.cms.dao.model.UserExample;
import com.zheng.cms.service.UserService;
import com.zheng.common.util.Paginator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 用户控制器
* @author shuzheng
* @date 2016年7月6日 下午6:16:25
*/
@Controller
@RequestMapping("/user")
public class UserController extends BaseController {
private static Logger _log = LoggerFactory.getLogger(UserController.class);
@Autowired
private UserService userService;
@ExceptionHandler(Exception.class)
public void exceptionHandler(Exception e) {
e.printStackTrace();
}
/**
* 首页
* @return
*/
@RequestMapping(value = {"", "index"})
public String index() {
return "redirect:/user/list";
}
/**
* 列表
* @param page
* @param rows
* @param request
* @return
*/
@RequestMapping("/list")
public String list(
@RequestParam(required = false, defaultValue = "1", value = "page") int page,
@RequestParam(required = false, defaultValue = "20", value = "rows") int rows,
HttpServletRequest request, Model model) {
UserExample userExample = new UserExample();
userExample.createCriteria()
.andUserIdGreaterThan(0);
userExample.setOffset((page -1) * rows);
userExample.setLimit(rows);
userExample.setDistinct(false);
userExample.setOrderByClause(" user_id asc ");
List<User> users = userService.getMapper().selectByExample(userExample);
model.addAttribute("users", users);
// 创建分页对象
long total = userService.getMapper().countByExample(userExample);
Paginator paginator = new Paginator();
paginator.setTotal(total);
paginator.setPage(page);
paginator.setRows(rows);
paginator.setParam("page");
paginator.setUrl(request.getRequestURI());
paginator.setQuery(request.getQueryString());
model.addAttribute("paginator", paginator);
return "/user/list";
}
/**
* 新增get
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add() {
return "/user/add";
}
/**
* 新增post
* @param user
* @param binding
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(@Valid User user, BindingResult binding) {
if (binding.hasErrors()) {
for (ObjectError error : binding.getAllErrors()) {
_log.error(error.getDefaultMessage());
}
return "/user/add";
}
user.setCtime(System.currentTimeMillis());
userService.getMapper().insertSelective(user);
_log.info("新增记录id为{}", user.getUserId());
return "redirect:/user/list";
}
/**
* 删除
* @param id
* @return
*/
@RequestMapping(value = "/delete/{id}",method = RequestMethod.GET)
public String delete(@PathVariable("id") int id) {
userService.getMapper().deleteByPrimaryKey(id);
return "redirect:/user/list";
}
/**
* 修改get
* @param id
* @param model
* @return
*/
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
public String update(@PathVariable("id") int id, Model model) {
model.addAttribute("user", userService.getMapper().selectByPrimaryKey(id));
return "/user/update";
}
/**
* 修改post
* @param id
* @param user
* @param binding
* @param model
* @return
*/
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String update(@PathVariable("id") int id, @Valid User user, BindingResult binding, Model model) {
if (binding.hasErrors()) {
model.addAttribute("errors", binding.getAllErrors());
return "user/update/" + id;
}
userService.getMapper().updateByPrimaryKeySelective(user);
return "redirect:/user/list";
}
/**
* 上传文件
* @param file
* @param request
* @return
* @throws IOException
*/
@ResponseBody
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public Object upload(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request) throws IOException {
// 返回结果
Map<String, Object> map = new HashMap<String, Object>();
// 判断上传文件类型
String contentType = file.getContentType().toLowerCase();
if ((!contentType.equals("image/jpeg")) &&
(!contentType.equals("image/pjpeg")) &&
(!contentType.equals("image/png")) &&
(!contentType.equals("image/x-png")) &&
(!contentType.equals("image/bmp")) &&
(!contentType.equals("image/gif"))) {
map.put(RESULT, FAILED);
map.put(DATA, "不支持该类型的文件!");
return map;
}
// 创建图片目录
String basePath = request.getSession().getServletContext().getRealPath("/attached");
String fileName = file.getOriginalFilename();
String savePath = basePath + "/images/";
File targetFile = new File(savePath, fileName);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
// 保存图片
file.transferTo(targetFile);
map.put(RESULT, SUCCESS);
map.put(DATA, targetFile.getAbsoluteFile());
return map;
}
/**
* ajax
* @param id
* @return
*/
@ResponseBody
@RequestMapping(value = "/ajax/{id}", method = RequestMethod.GET)
public Object ajax(@PathVariable int id) {
return userService.getMapper().selectByPrimaryKey(id);
}
}

View File

@ -1,134 +0,0 @@
package com.zheng.cms.controller.manage;
import com.zheng.cms.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.common.util.Paginator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* 文章控制器
* Created by shuzheng on 2016/11/14.
*/
@Controller
@RequestMapping("/manage/article")
public class CmsArticleController extends BaseController {
private final static Logger _log = LoggerFactory.getLogger(CmsArticleController.class);
@Autowired
private CmsArticleService cmsArticleService;
/**
* 列表
* @param page 当前页码
* @param rows 每页条数
* @param desc 降序排序
* @param request
* @param model
* @return
*/
@RequestMapping("/list")
public String list(
@RequestParam(required = false, defaultValue = "1", value = "page") int page,
@RequestParam(required = false, defaultValue = "20", value = "rows") int rows,
@RequestParam(required = false, defaultValue = "true", value = "desc") boolean desc,
HttpServletRequest request, Model model) {
// 数据列表
CmsArticleExample cmsArticleExample = new CmsArticleExample();
cmsArticleExample.setOffset((page - 1) * rows);
cmsArticleExample.setLimit(rows);
cmsArticleExample.setOrderByClause(desc ? "orders desc" : "orders asc");
List<CmsArticle> articles = cmsArticleService.getMapper().selectByExample(cmsArticleExample);
// 分页对象
long total = cmsArticleService.getMapper().countByExample(cmsArticleExample);
Paginator paginator = new Paginator(total, page, rows, request);
model.addAttribute("articles", articles);
model.addAttribute("paginator", paginator);
return "/manage/article/list";
}
/**
* 新增get
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add() {
return "/manage/article/add";
}
/**
* 新增post
* @param cmsArticle
* @param model
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(CmsArticle cmsArticle, Model model) {
long time = System.currentTimeMillis();
cmsArticle.setCtime(time);
cmsArticle.setOrders(time);
int count = cmsArticleService.getMapper().insertSelective(cmsArticle);
model.addAttribute("count", count);
_log.info("新增记录id为{}", cmsArticle.getArticleId());
return "redirect:/manage/article/list";
}
/**
* 删除
* @param ids
* @param model
* @return
*/
@RequestMapping(value = "/delete/{ids}",method = RequestMethod.GET)
public String delete(@PathVariable("ids") String ids, Model model) {
int count = cmsArticleService.deleteByPrimaryKeys(ids);
model.addAttribute("count", count);
return "redirect:/manage/article/list";
}
/**
* 修改get
* @param id
* @param model
* @return
*/
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
public String update(@PathVariable("id") int id, Model model) {
CmsArticle article = cmsArticleService.getMapper().selectByPrimaryKey(id);
model.addAttribute("article", article);
return "/manage/article/update";
}
/**
* 修改post
* @param id
* @param cmsArticle
* @param model
* @return
*/
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String update(@PathVariable("id") int id, CmsArticle cmsArticle, Model model) {
int count = cmsArticleService.getMapper().updateByPrimaryKeySelective(cmsArticle);
model.addAttribute("count", count);
model.addAttribute("id", id);
return "redirect:/manage/article/list";
}
}

View File

@ -1,133 +0,0 @@
package com.zheng.cms.controller.manage;
import com.zheng.cms.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.common.util.Paginator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* 类目控制器
* Created by shuzheng on 2016/11/14.
*/
@Controller
@RequestMapping("/manage/category")
public class CmsCategoryController extends BaseController {
private final static Logger _log = LoggerFactory.getLogger(CmsCategoryController.class);
@Autowired
private CmsCategoryService cmsCategoryService;
/**
* 列表
* @param page 当前页码
* @param rows 每页条数
* @param desc 降序排序
* @param request
* @param model
* @return
*/
@RequestMapping("/list")
public String list(
@RequestParam(required = false, defaultValue = "1", value = "page") int page,
@RequestParam(required = false, defaultValue = "20", value = "rows") int rows,
@RequestParam(required = false, defaultValue = "false", value = "desc") boolean desc,
HttpServletRequest request, Model model) {
// 数据列表
CmsCategoryExample cmsCategoryExample = new CmsCategoryExample();
cmsCategoryExample.setOffset((page - 1) * rows);
cmsCategoryExample.setLimit(rows);
cmsCategoryExample.setOrderByClause(desc ? "orders desc" : "orders asc");
List<CmsCategory> categorys = cmsCategoryService.getMapper().selectByExample(cmsCategoryExample);
// 分页对象
long total = cmsCategoryService.getMapper().countByExample(cmsCategoryExample);
Paginator paginator = new Paginator(total, page, rows, request);
model.addAttribute("categorys", categorys);
model.addAttribute("paginator", paginator);
return "/manage/category/list";
}
/**
* 新增get
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add() {
return "/manage/category/add";
}
/**
* 新增post
* @param cmsCategory
* @param model
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(CmsCategory cmsCategory, Model model) {
long time = System.currentTimeMillis();
cmsCategory.setCtime(time);
cmsCategory.setOrders(time);
int count = cmsCategoryService.getMapper().insertSelective(cmsCategory);
model.addAttribute("count", count);
_log.info("新增记录id为{}", cmsCategory.getCategoryId());
return "redirect:/manage/category/list";
}
/**
* 删除
* @param ids
* @param model
* @return
*/
@RequestMapping(value = "/delete/{ids}",method = RequestMethod.GET)
public String delete(@PathVariable("ids") String ids, Model model) {
int count = cmsCategoryService.deleteByPrimaryKeys(ids);
model.addAttribute("count", count);
return "redirect:/manage/category/list";
}
/**
* 修改get
* @param id
* @param model
* @return
*/
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
public String update(@PathVariable("id") int id, Model model) {
CmsCategory category = cmsCategoryService.getMapper().selectByPrimaryKey(id);
model.addAttribute("category", category);
return "/manage/category/update";
}
/**
* 修改post
* @param id
* @param cmsCategory
* @param model
* @return
*/
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String update(@PathVariable("id") int id, CmsCategory cmsCategory, Model model) {
int count = cmsCategoryService.getMapper().updateByPrimaryKeySelective(cmsCategory);
model.addAttribute("count", count);
model.addAttribute("id", id);
return "redirect:/manage/category/list";
}
}

View File

@ -1,131 +0,0 @@
package com.zheng.cms.controller.manage;
import com.zheng.cms.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.common.util.Paginator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* 评论控制器
* Created by shuzheng on 2016/11/14.
*/
@Controller
@RequestMapping("/manage/comment")
public class CmsCommentController extends BaseController {
private final static Logger _log = LoggerFactory.getLogger(CmsCommentController.class);
@Autowired
private CmsCommentService cmsCommentService;
/**
* 列表
* @param page 当前页码
* @param rows 每页条数
* @param desc 降序排序
* @param request
* @param model
* @return
*/
@RequestMapping("/list")
public String list(
@RequestParam(required = false, defaultValue = "1", value = "page") int page,
@RequestParam(required = false, defaultValue = "20", value = "rows") int rows,
@RequestParam(required = false, defaultValue = "true", value = "desc") boolean desc,
HttpServletRequest request, Model model) {
// 数据列表
CmsCommentExample cmsCommentExample = new CmsCommentExample();
cmsCommentExample.setOffset((page - 1) * rows);
cmsCommentExample.setLimit(rows);
cmsCommentExample.setOrderByClause(desc ? "comment_id desc" : "comment_id asc");
List<CmsComment> comments = cmsCommentService.getMapper().selectByExample(cmsCommentExample);
// 分页对象
long total = cmsCommentService.getMapper().countByExample(cmsCommentExample);
Paginator paginator = new Paginator(total, page, rows, request);
model.addAttribute("comments", comments);
model.addAttribute("paginator", paginator);
return "/manage/comment/list";
}
/**
* 新增get
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add() {
return "/manage/comment/add";
}
/**
* 新增post
* @param cmsComment
* @param model
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(CmsComment cmsComment, Model model) {
cmsComment.setCtime(System.currentTimeMillis());
int count = cmsCommentService.getMapper().insertSelective(cmsComment);
model.addAttribute("count", count);
_log.info("新增记录id为{}", cmsComment.getArticleId());
return "redirect:/manage/comment/list";
}
/**
* 删除
* @param ids
* @param model
* @return
*/
@RequestMapping(value = "/delete/{ids}",method = RequestMethod.GET)
public String delete(@PathVariable("ids") String ids, Model model) {
int count = cmsCommentService.deleteByPrimaryKeys(ids);
model.addAttribute("count", count);
return "redirect:/manage/comment/list";
}
/**
* 修改get
* @param id
* @param model
* @return
*/
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
public String update(@PathVariable("id") int id, Model model) {
CmsComment comment = cmsCommentService.getMapper().selectByPrimaryKey(id);
model.addAttribute("comment", comment);
return "/manage/comment/update";
}
/**
* 修改post
* @param id
* @param cmsComment
* @param model
* @return
*/
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String update(@PathVariable("id") int id, CmsComment cmsComment, Model model) {
int count = cmsCommentService.getMapper().updateByPrimaryKeySelective(cmsComment);
model.addAttribute("count", count);
model.addAttribute("id", id);
return "redirect:/manage/comment/list";
}
}

View File

@ -1,133 +0,0 @@
package com.zheng.cms.controller.manage;
import com.zheng.cms.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.common.util.Paginator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* 标签控制器
* Created by shuzheng on 2016/11/14.
*/
@Controller
@RequestMapping("/manage/tag")
public class CmsTagController extends BaseController {
private final static Logger _log = LoggerFactory.getLogger(CmsTagController.class);
@Autowired
private CmsTagService cmsTagService;
/**
* 列表
* @param page 当前页码
* @param rows 每页条数
* @param desc 降序排序
* @param request
* @param model
* @return
*/
@RequestMapping("/list")
public String list(
@RequestParam(required = false, defaultValue = "1", value = "page") int page,
@RequestParam(required = false, defaultValue = "20", value = "rows") int rows,
@RequestParam(required = false, defaultValue = "false", value = "desc") boolean desc,
HttpServletRequest request, Model model) {
// 数据列表
CmsTagExample cmsTagExample = new CmsTagExample();
cmsTagExample.setOffset((page - 1) * rows);
cmsTagExample.setLimit(rows);
cmsTagExample.setOrderByClause(desc ? "orders desc" : "orders asc");
List<CmsTag> tags = cmsTagService.getMapper().selectByExample(cmsTagExample);
// 分页对象
long total = cmsTagService.getMapper().countByExample(cmsTagExample);
Paginator paginator = new Paginator(total, page, rows, request);
model.addAttribute("tags", tags);
model.addAttribute("paginator", paginator);
return "/manage/tag/list";
}
/**
* 新增get
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add() {
return "/manage/tag/add";
}
/**
* 新增post
* @param cmsTag
* @param model
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(CmsTag cmsTag, Model model) {
long time = System.currentTimeMillis();
cmsTag.setCtime(time);
cmsTag.setOrders(time);
int count = cmsTagService.getMapper().insertSelective(cmsTag);
model.addAttribute("count", count);
_log.info("新增记录id为{}", cmsTag.getTagId());
return "redirect:/manage/tag/list";
}
/**
* 删除
* @param ids
* @param model
* @return
*/
@RequestMapping(value = "/delete/{ids}",method = RequestMethod.GET)
public String delete(@PathVariable("ids") String ids, Model model) {
int count = cmsTagService.deleteByPrimaryKeys(ids);
model.addAttribute("count", count);
return "redirect:/manage/tag/list";
}
/**
* 修改get
* @param id
* @param model
* @return
*/
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
public String update(@PathVariable("id") int id, Model model) {
CmsTag tag = cmsTagService.getMapper().selectByPrimaryKey(id);
model.addAttribute("tag", tag);
return "/manage/tag/update";
}
/**
* 修改post
* @param id
* @param cmsTag
* @param model
* @return
*/
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String update(@PathVariable("id") int id, CmsTag cmsTag, Model model) {
int count = cmsTagService.getMapper().updateByPrimaryKeySelective(cmsTag);
model.addAttribute("count", count);
model.addAttribute("id", id);
return "redirect:/manage/tag/list";
}
}

View File

@ -1,47 +0,0 @@
package com.zheng.cms.jms;
import com.zheng.cms.dao.model.User;
import com.zheng.cms.service.UserService;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
/**
* MQ消费者
* Created by ZhangShuzheng on 2016/11/24.
*/
public class defaultQueueMessageListener implements MessageListener {
private static Logger _log = LoggerFactory.getLogger(defaultQueueMessageListener.class);
@Autowired
ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Autowired
UserService userService;
public void onMessage(final Message message) {
// 使用线程池多线程处理
threadPoolTaskExecutor.execute(new Runnable() {
public void run() {
TextMessage textMessage = (TextMessage) message;
try {
String text = textMessage.getText();
JSONObject json = JSONObject.fromObject(text);
User user = (User) JSONObject.toBean(json, User.class);
userService.getMapper().insertSelective(user);
_log.info("zheng-cms-web接收到{}", text);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}

View File

@ -1,58 +0,0 @@
package com.zheng.cms.schedule;
import com.taobao.pamirs.schedule.IScheduleTaskDealSingle;
import com.taobao.pamirs.schedule.TaskItemDefine;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
/**
* 测试任务
* Created by zhangshuzheng on 2016/11/14.
*/
public class LongSchedule implements IScheduleTaskDealSingle<Long> {
/**
* 执行单个任务
* @param item Object
* @param ownSign 当前环境名称
* @throws Exception
*/
@Override
public boolean execute(Long item, String ownSign) throws Exception {
System.out.println("执行任务:" + item);
return true;
}
/**
* 根据条件查询当前调度服务器可处理的任务
* @param taskParameter 任务的自定义参数
* @param ownSign 当前环境名称
* @param taskItemNum 当前任务类型的任务队列数量
* @param taskItemList 当前调度服务器分配到的可处理队列
* @param eachFetchDataNum 每次获取数据的数量
* @return
* @throws Exception
*/
@Override
public List<Long> selectTasks(String taskParameter, String ownSign, int taskItemNum, List<TaskItemDefine> taskItemList, int eachFetchDataNum) throws Exception {
List<Long> allDrawList = new ArrayList<>();
allDrawList.add(System.currentTimeMillis());
return allDrawList;
}
/**
* 获取任务的比较器,只有在NotSleep模式下需要用到
* @return
*/
@Override
public Comparator<Long> getComparator() {
return new Comparator<Long>() {
public int compare(Long o1, Long o2) {
return o1.compareTo(o2);
}
};
}
}

View File

@ -1,63 +0,0 @@
package com.zheng.cms.schedule;
import com.taobao.pamirs.schedule.IScheduleTaskDealSingle;
import com.taobao.pamirs.schedule.TaskItemDefine;
import java.util.*;
/**
* 测试任务
* Created by zhangshuzheng on 2016/11/14.
*/
public class MapSchedule implements IScheduleTaskDealSingle<Map> {
/**
* 执行单个任务
* @param item Object
* @param ownSign 当前环境名称
* @throws Exception
*/
@Override
public boolean execute(Map item, String ownSign) throws Exception {
System.out.println("执行任务:" + item);
return true;
}
/**
* 根据条件查询当前调度服务器可处理的任务
* @param taskParameter 任务的自定义参数
* @param ownSign 当前环境名称
* @param taskItemNum 当前任务类型的任务队列数量
* @param taskItemList 当前调度服务器分配到的可处理队列
* @param eachFetchDataNum 每次获取数据的数量
* @return
* @throws Exception
*/
@Override
public List<Map> selectTasks(String taskParameter, String ownSign, int taskItemNum, List<TaskItemDefine> taskItemList, int eachFetchDataNum) throws Exception {
List<Map> allDrawList = new ArrayList<>();
Map map = new HashMap();
map.put("ID", System.currentTimeMillis());
allDrawList.add(map);
return allDrawList;
}
/**
* 获取任务的比较器,只有在NotSleep模式下需要用到
* @return
*/
@Override
public Comparator<Map> getComparator() {
return new Comparator<Map>() {
public int compare(Map o1, Map o2) {
Long l1 = (Long) o1.get("ID");
Long l2 = (Long) o2.get("ID");
return l1.compareTo(l2);
}
public boolean equals(Object obj) {
return this == obj;
}
};
}
}

View File

@ -1,8 +0,0 @@
package com.zheng.cms.task;
/**
* Created by ZhangShuzheng on 2016/11/1.
*/
public interface TestTask {
public void test();
}

View File

@ -1,19 +0,0 @@
package com.zheng.cms.task.impl;
import com.zheng.cms.task.TestTask;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* Created by ZhangShuzheng on 2016/11/1.
*/
@Component
public class TestTaskImpl implements TestTask {
@Scheduled(cron = "0 0/1 * * * ?")
@Override
public void test() {
System.out.println("Task");
}
}