赞
踩
源码获取:博客首页 "资源" 里下载!
技术框架: HTML+CSS+JavaScript+jsp+mysql+Spring+SpringMVC+mybatis+Spring boot
数据库: Mysql数据库
-
-
- /**
- *
- *管理员控制层
- */
- @Controller
- @RequestMapping("/admin")
- @Scope("prototype")
- public class AdminController {
-
- private static final Logger logger = LoggerFactory.getLogger(AdminController.class);
- private ReturnResult returnResult = new ReturnResult();
-
- @Resource(name = "adminService")
- private IAdminService adminService;
-
- /**
- * 管理员登录
- * @param admin
- * @param session
- * @return
- */
- @RequestMapping(value = "login", method = RequestMethod.POST)
- @ResponseBody
- public ReturnResult login(TAdmin admin, HttpSession session) {
- returnResult.setStatus(ReturnCodeType.FAILURE);
- try {
- admin = adminService.login(admin);
- if (admin != null) {
- admin.setPassword(null);
- session.setAttribute("admin", admin);
- returnResult.setStatus(ReturnCodeType.SUCCESS);
- }
- } catch (Exception e) {
- logger.error("登录失败:" + e);
-
- }
- return returnResult;
-
- }
-
- /**
- * 从session获取管理员信息
- * @param session
- * @return
- */
- @RequestMapping(value="getAdminInfo", method = RequestMethod.POST)
- @ResponseBody
- public ReturnResult getAdminInfo(HttpSession session) {
- returnResult.setStatus(ReturnCodeType.FAILURE);
- TAdmin admin = (TAdmin) session.getAttribute("admin");
- if (admin != null) {
- returnResult.setStatus(ReturnCodeType.SUCCESS).setData(admin);
- } else {
- logger.info("获取管理员信息失败:管理员未登录");
- }
- return returnResult;
- }
-
- /**
- * 退出
- * @param session
- * @return
- */
- @RequestMapping(value="logout", method = RequestMethod.POST)
- @ResponseBody
- public ReturnResult logout(HttpSession session) {
- session.invalidate();
- return returnResult.setStatus(ReturnCodeType.SUCCESS);
- }
-
- }

- /**
- * 评论控制层
- *
- */
- @Controller
- @Scope("prototype")
- public class CommentController {
-
- private static final Logger logger = LoggerFactory.getLogger(CommentController.class);
- private ReturnResult returnResult = new ReturnResult();
-
- @Resource(name = "commentService")
- private ICommentService commentService;
-
- /**
- * 添加评论
- *
- * @param comment
- * @param HttpServletRequest
- * @return
- */
- @RequestMapping(value = "addComment", method = RequestMethod.POST)
- @ResponseBody
- public ReturnResult addInfo(TComment comment,HttpSession session) {
- returnResult.setStatus(ReturnCodeType.FAILURE);
- try {
- TUser user = (TUser) session.getAttribute("user");
- comment.setUserid(user.getId());
- comment.setCreatetime(new Date());
- commentService.insert(comment);
- returnResult.setStatus(ReturnCodeType.SUCCESS);
- } catch (Exception e) {
- logger.error("新增comment失败" + e);
- }
- return returnResult;
-
- }
-
- /**
- * 删除评论
- *
- * @param comment
- * @param HttpServletRequest
- * @return
- */
- @RequestMapping(value = "deleteComment", method = RequestMethod.POST)
- @ResponseBody
- public ReturnResult deleteComment(Integer id) {
- returnResult.setStatus(ReturnCodeType.FAILURE);
- try {
-
- commentService.deleteByPrimaryKey(id);
- returnResult.setStatus(ReturnCodeType.SUCCESS);
- } catch (Exception e) {
- logger.error("删除comment失败" + e);
- }
- return returnResult;
-
- }
- /**
- * 根据摄影师id查询评论
- *
- * @param comment
- * @param HttpServletRequest
- * @return
- */
- @RequestMapping(value = "getCommentByPid", method = RequestMethod.GET)
- @ResponseBody
- public ReturnResult getCommentByPid(Integer pid) {
- returnResult.setStatus(ReturnCodeType.FAILURE);
- try {
-
-
- returnResult.setStatus(ReturnCodeType.SUCCESS).setData(commentService.selectBySQL("SELECT a.`comment`,a.createTime,b.`name` FROM t_comment a,t_user b where a.userId=b.id AND a.photographerId="+pid));
- } catch (Exception e) {
- logger.error("根据摄影师id查询评论" + e);
- }
- return returnResult;
-
- }
-
- /**
- * 分页获取comment
- * @return
- */
- @RequestMapping(value = "getCommentListByPage", method = RequestMethod.POST)
- @ResponseBody
- public ReturnResult getCommentListByPage(PageVO page) {
- returnResult.setStatus(ReturnCodeType.FAILURE);
- try {
- Map<String, Object> resultMap = new HashMap<String, Object>();
- StringBuffer sql = new StringBuffer("SELECT DISTINCT * FROM t_comment WHERE 1=1");
-
-
- List<Map<String, Object>> results = commentService.selectPageBySQL(sql.toString(), page.getPage() - 1,
- page.getRows());
- if (!results.isEmpty() && results != null) {
- int total = commentService.selectCount(new TComment());
- int rows = page.getRows();
- rows = rows == 0 ? 10 : rows;
- resultMap.put("total", (total % rows != 0 ? (total / rows + 1) : (total / rows)));
- resultMap.put("page", page.getPage());
- resultMap.put("records", total);
- resultMap.put("rows", results);
- returnResult.setStatus(ReturnCodeType.SUCCESS).setData(resultMap);
- }
- }catch (Exception e) {
- logger.error("分页获取comment失败" + e);
- }
- return returnResult;
- }
-
-
- }

- /**
- *
- *景点信息控制层
- */
- @Controller
- @Scope("prototype")
- public class SpotsController {
-
- private static final Logger logger = LoggerFactory.getLogger(SpotsController.class);
- private ReturnResult returnResult = new ReturnResult();
-
- @Resource(name = "spotsService")
- private ISpotsService spotsService;
-
- /**
- * 添加拍摄景点
- *
- * @param spots
- * @param HttpServletRequest
- * @return
- */
- @RequestMapping(value = "addSpots", method = RequestMethod.POST)
- @ResponseBody
- public ReturnResult addSpots(TSpots spots, HttpServletRequest request) {
- returnResult.setStatus(ReturnCodeType.FAILURE);
- try {
-
- Map<String, String> map = OperationFileUtil.multiFileUpload(request,
- request.getServletContext().getRealPath("/") + "uploads\\spots\\");
- String filePath = "";
- for (Map.Entry<String, String> entry : map.entrySet()) {
- filePath = entry.getValue();
- }
- filePath = filePath.replace(request.getServletContext().getRealPath("/"), "/");
- spots.setPath(filePath);
- spots.setCreatetime(new Date());
- spotsService.insert(spots);
- returnResult.setStatus(ReturnCodeType.SUCCESS);
- } catch (Exception e) {
- logger.error("新增spots失败" + e);
- }
- return returnResult;
-
- }
-
-
- /**
- * 修改spots
- * @param spots
- * @return
- */
- @RequestMapping(value = "updateSpots", method = RequestMethod.POST)
- @ResponseBody
- public ReturnResult updateSpots(TSpots spots) {
- returnResult.setStatus(ReturnCodeType.FAILURE);
- try {
- spotsService.updateBySQL("UPDATE t_spots SET name='" + spots.getName() + "',content='"+spots.getContent()+"', status="+spots.getStatus()+" WHERE id=" + spots.getId());
- returnResult.setStatus(ReturnCodeType.SUCCESS);
- } catch (Exception e) {
- logger.error("修改spots失败" + e);
- }
- return returnResult;
- }
-
- /**
- * 分页获取spots
- * @return
- */
- @RequestMapping(value = "getSpotsListByPage", method = RequestMethod.POST)
- @ResponseBody
- public ReturnResult getSpotsListByPage(PageVO page) {
- returnResult.setStatus(ReturnCodeType.FAILURE);
- try {
- Map<String, Object> resultMap = new HashMap<String, Object>();
- StringBuffer sql = new StringBuffer("SELECT DISTINCT * FROM t_spots WHERE 1=1");
-
-
- List<Map<String, Object>> results = spotsService.selectPageBySQL(sql.toString(), page.getPage() - 1,
- page.getRows());
- if (!results.isEmpty() && results != null) {
- int total = spotsService.selectCount(new TSpots());
- int rows = page.getRows();
- rows = rows == 0 ? 10 : rows;
- resultMap.put("total", (total % rows != 0 ? (total / rows + 1) : (total / rows)));
- resultMap.put("page", page.getPage());
- resultMap.put("records", total);
- resultMap.put("rows", results);
- returnResult.setStatus(ReturnCodeType.SUCCESS).setData(resultMap);
- }
- }catch (Exception e) {
- logger.error("分页获取spots失败" + e);
- }
- return returnResult;
- }
- /**
- * 根据获取id spots
- * @param id
- * @return
- */
- @RequestMapping(value = "getSpotsById", method = RequestMethod.POST)
- @ResponseBody
- public ReturnResult getSpotsById(Integer id) {
- returnResult.setStatus(ReturnCodeType.FAILURE);
- try {
- returnResult.setStatus(ReturnCodeType.SUCCESS).setData(spotsService.selectByPrimaryKey(id));
- }catch (Exception e) {
- logger.error("根据获取spots失败" + e);
- }
- return returnResult;
- }
-
- /**
- * 获取所有启用的spots
- * @return
- */
- @RequestMapping(value = "getAllSpots", method = RequestMethod.POST)
- @ResponseBody
- public ReturnResult getAllSpots() {
- returnResult.setStatus(ReturnCodeType.FAILURE);
- try {
- returnResult.setStatus(ReturnCodeType.SUCCESS).setData(spotsService.getAllSpots());
- } catch (Exception e) {
- logger.error("获取所有启用spots失败" + e);
- }
- return returnResult;
- }
- /**
- * 获取所有5条启用的spots
- * @return
- */
- @RequestMapping(value = "getFiveSpots", method = RequestMethod.POST)
- @ResponseBody
- public ReturnResult getFiveSpots() {
- returnResult.setStatus(ReturnCodeType.FAILURE);
- try {
- returnResult.setStatus(ReturnCodeType.SUCCESS).setData(spotsService.selectBySQL("select * from t_spots ORDER BY id DESC limit 0,5"));
- } catch (Exception e) {
- logger.error("获取所有5条启用的spots失败" + e);
- }
- return returnResult;
- }
-
- }

源码获取:博客首页 "资源" 里下载!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。