当前位置: 首页 > 编程日记 > 正文

Java项目:生活旅行分享平台(java+Springboot+JPA+Jsp+Html+js+Ajax+maven+mysql)

源码获取:博客首页 "资源" 里下载!

一、项目运行

环境配置:

Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

Springboot+ SpringMVC + JPA+ Jsp + Html+ JavaScript + JQuery + Ajax + maven等等

评论业务控制器:

/*** 评论控制器* @author yy**/
@RestController
@RequestMapping("/comment")
public class CommentController {@Resourceprivate CommentService commentService;@Resourceprivate ArticleService articleService;@Resourceprivate ReplyService replyService;/*** 分页查询评论* @param comment* @param page* @param pageSize* @return*/@RequestMapping("/list")public Map<String, Object> commentList(Comment comment, @RequestParam(value = "page", required = false) Integer page,@RequestParam(value = "pageSize", required = false) Integer pageSize) {List<Comment> commentList = commentService.list(comment, null, null, page - 1, pageSize, null);Long total = commentService.getCount(comment, null, null, null);int totalPage = (int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);Map<String, Object> resultMap = new HashMap<String, Object>();resultMap.put("totalPage", totalPage);resultMap.put("data", commentList);return resultMap;}/*** 分页查询评论* @param page* @param pageSize* @return*/@RequestMapping("/massageList")public Map<String, Object> massageList(@RequestParam(value = "page", required = false) Integer page,@RequestParam(value = "pageSize", required = false) Integer pageSize) {List<Comment> commentList = commentService.massageList(page - 1, pageSize);Long total = commentService.getCount2();int totalPage = (int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);Map<String, Object> resultMap = new HashMap<String, Object>();resultMap.put("totalPage", totalPage);resultMap.put("data", commentList);return resultMap;}/*** 添加评论* @Title: add* @param comment  评论实体* @return  参数说明* @return Map<String,Object>    返回类型* @throws*/@RequestMapping("/add")public Map<String, Object> add(Comment comment, HttpSession session) {User currentUser = (User) session.getAttribute("user");Map<String, Object> resultMap = new HashMap<String, Object>();comment.setCommentDate(new Date());comment.setUser(currentUser);commentService.add(comment);if (comment.getArticle() != null) {articleService.increaseComment(comment.getArticle().getArticleId());}resultMap.put("comment", comment);resultMap.put("success", true);return resultMap;}}

回复业务控制器:

/*** 回复控制器* @author yy**/
@RestController
@RequestMapping("/reply")
public class ReplyController {@Resourceprivate ReplyService replyService;/*** 获取回复* @param reply* @return*/@RequestMapping("/list")public Map<String, Object> replyList(Reply reply) {List<Reply> replyList = replyService.list(reply);Map<String, Object> resultMap = new HashMap<String, Object>();resultMap.put("data", replyList);return resultMap;}/*** 添加回复* @param reply* @return*/@RequestMapping("/add")public Map<String, Object> add(Reply reply, HttpSession session) {User currentUser = (User) session.getAttribute("user");Map<String, Object> resultMap = new HashMap<String, Object>();reply.setReplyDate(new Date());reply.setUser(currentUser);replyService.add(reply);resultMap.put("reply", reply);resultMap.put("success", true);return resultMap;}}

管理员业务控制器:

/*** 管理员控制器* @author yy**/
@RestController
@RequestMapping("/admin")
public class AdminController {@Value("${MD5Salt}")private String salt; // md5加密盐@Resourceprivate AdminService adminService;@Resourceprivate UserService userService;@Resourceprivate ArticleService articleService;@Resourceprivate ClassifyService classifyService;/*** 后台管理员登录验证* @param admin* @param request* @return*/@RequestMapping("/login")public ModelAndView login(Admin admin, HttpServletRequest request) {ModelAndView mav = new ModelAndView();HttpSession session = request.getSession();try {Admin resultUser = adminService.findByUserNameAndPassword(admin.getUserName(), admin.getPassword());if (resultUser == null) {mav.addObject("errorInfo", "用户名或者密码错误!");mav.setViewName("/login");} else {session.setAttribute("adminUser", resultUser);// 统计用户总数Long userCount = userService.getCount();// 统计今天注册Long userRegCount = userService.getTodayRegistCount(new User(), "1", "1");// 统计今日登录Long userLogCount = userService.getCount(new User(), "1", "1");// 统计笔记总数Long artCount = articleService.getCount();// 统计笔记分类Long classCount = classifyService.getCount();session.setAttribute("userCount", userCount);session.setAttribute("userRegCount", userRegCount);session.setAttribute("userLogCount", userLogCount);session.setAttribute("artCount", artCount);session.setAttribute("classCount", classCount);mav.addObject("success", true);mav.setViewName("/admin/index");}} catch (Exception e) { // 用户名密码错误e.printStackTrace();mav.addObject("admin", admin);mav.addObject("errorInfo", "用户名或者密码错误!");mav.setViewName("/login");}return mav;}/*** 查看个人信息* * @return*/@RequestMapping("viewPerson")public ModelAndView viewPerson(HttpServletRequest request) {Admin admin = (Admin) request.getSession().getAttribute("adminUser");ModelAndView mav = new ModelAndView();Admin u = adminService.findById(admin.getAdminId());mav.addObject("user", u);mav.setViewName("/admin/adminViewPerson");return mav;}/*** 保存用户信息* * @param user* @return*/@RequestMapping("/save")public ModelAndView save(Admin user) {ModelAndView mav = new ModelAndView();adminService.save(user);mav.setViewName("/admin/index");return mav;}
}

用户业务控制器:

/*** 用户控制器**/
@RestController
@RequestMapping("/admin/user")
public class UserAdminController {@Resourceprivate UserService userService;@Value("${MD5Salt}")private String salt; // md5加密盐/*** 根据ID查找用户* @param userId* @return*/@RequestMapping("/findById")public Map<String, Object> findById(Integer userId) {Map<String, Object> resultMap = new HashMap<String, Object>();User user = userService.findById(userId);resultMap.put("errorNo", 0);resultMap.put("data", user);return resultMap;}/*** 分页查询用户* @param user* @param registrationDates* @param page* @param limit* @return*/@RequestMapping("/list")public Map<String, Object> list(User user,@RequestParam(value = "latelyLoginTimes", required = false) String latelyLoginTimes,@RequestParam(value = "page", required = false) Integer page,@RequestParam(value = "pageSize", required = false) Integer pageSize) {String s_bregistrationDate = null; // 开始时间String s_eregistrationDate = null; // 结束时间if (StringUtil.isNotEmpty(latelyLoginTimes)) {String[] strs = latelyLoginTimes.split(" - "); // 拆分时间段s_bregistrationDate = strs[0];s_eregistrationDate = strs[1];}List<User> userList = userService.list(user, s_bregistrationDate, s_eregistrationDate, page - 1, pageSize);Long total = userService.getCount(user, s_bregistrationDate, s_eregistrationDate);Map<String, Object> resultMap = new HashMap<String, Object>();resultMap.put("errorNo", 0);resultMap.put("data", userList);resultMap.put("total", total);return resultMap;}@RequestMapping("/delete")public Map<String, Object> delete(Integer userId) {Map<String, Object> resultMap = new HashMap<String, Object>();userService.delete(userId);resultMap.put("errorNo", 0);return resultMap;}/*** 取消关注* @param request* @param userId* @return*/@RequestMapping("/removeFocusUser")public ModelAndView removeFocusUser(HttpServletRequest request, String userId) {ModelAndView mav = new ModelAndView();User user = (User) request.getSession().getAttribute("user");// 当前登录用户String userIds = user.getUserIds();List<String> tempList = Arrays.asList(userIds.split(","));List<String> lineIdList = new ArrayList<>(tempList);lineIdList.remove(userId);String ret = StringUtils.join(lineIdList, ",");user.setUserIds(ret);userService.save(user);mav.setViewName("redirect:/viewFocusUser");return mav;}/*** 关注用户* @param request* @param userId* @return*/@RequestMapping("/addFocusUser")public ModelAndView addFocusUser(HttpServletRequest request, String userId) {ModelAndView mav = new ModelAndView();User user = (User) request.getSession().getAttribute("user");// 当前登录用户String userIds = user.getUserIds();List<String> tempList = Arrays.asList(userIds.split(","));List<String> lineIdList = new ArrayList<>(tempList);lineIdList.add(userId);String ret = StringUtils.join(lineIdList, ",");user.setUserIds(ret);userService.save(user);mav.setViewName("redirect:/viewFocusUser");return mav;}@RequestMapping("/addFocusUser/{userId}")public ModelAndView addFocusUser(@PathVariable(value = "userId", required = false) Integer userId,HttpSession session) {ModelAndView mav = new ModelAndView();User user = (User) session.getAttribute("user");// 当前登录用户String userIds = user.getUserIds();List<String> tempList = new ArrayList<>();if (userIds != null) {tempList = Arrays.asList(userIds.split(","));}List<String> lineIdList = new ArrayList<>(tempList);lineIdList.add(userId.toString());String ret = StringUtils.join(lineIdList, ",");user.setUserIds(ret);userService.save(user);mav.setViewName("redirect:/viewFocusUser");return mav;}/*** 取消收藏* @param request* @param userId* @return*/@RequestMapping("/removeCollection")public ModelAndView removeCollection(HttpServletRequest request, String artId) {ModelAndView mav = new ModelAndView();User user = (User) request.getSession().getAttribute("user");// 当前登录用户String artIds = user.getArticleIds();List<String> tempList = Arrays.asList(artIds.split(","));List<String> lineIdList = new ArrayList<>(tempList);lineIdList.remove(artId);String ret = StringUtils.join(lineIdList, ",");user.setArticleIds(ret);userService.save(user);mav.setViewName("redirect:/viewCollection");return mav;}/*** 收藏* @param request* @param userId* @return*/@RequestMapping("/addCollection")public ModelAndView addCollection(HttpServletRequest request, String artId) {ModelAndView mav = new ModelAndView();User user = (User) request.getSession().getAttribute("user");// 当前登录用户String artIds = user.getArticleIds();List<String> tempList = Arrays.asList(artIds.split(","));List<String> lineIdList = new ArrayList<>(tempList);lineIdList.add(artId);String ret = StringUtils.join(lineIdList, ",");user.setArticleIds(ret);userService.save(user);mav.setViewName("redirect:/viewCollection");return mav;}
}

源码获取:博客首页 "资源" 里下载! 

相关文章:

Servlet和SpringMVC补课

1.web.xml加载顺序 http://mianhuaman.iteye.com/blog/1105522 关键点&#xff1a;ServletContext -> context-param -> listener -> filter -> servlet 2.beans xmlns http://www.w3school.com.cn/xml/xml_namespaces.asp 用于避免元素命名冲突。在Spring中应用极…

gdb debug

1. dir 添加源代码查找路径 一般工程的代码会有多路径&#xff0c;gdb会在当前目录下搜索符号对应的代码。利用dir <path> 可以添加代码搜索路径&#xff1b; 例如工程目录&#xff1a; ./ ./dir_1/ ./dir_2/ 可以用如下命令添加代码搜索路径&#xff1a; dir dir…

Java项目:嘟嘟图片展览馆管理系统(java+Springboot+SpringMVC+JPA+Jsp+maven+mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目运行 环境配置&#xff1a; Jdk1.8 Tomcat8.5 mysql Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09; 项目技术&#xff1a; Springboot SpringMVC JPA Jsp Htm…

javascript编译与运行机理(1)--

随着学习js的深入就越想了解其内部的运行机理&#xff0c;看了很多文章&#xff0c;感觉下面总结的不错。但囿于个人水平&#xff0c;只是达到了理解层面&#xff0c;还不能提出自己的见解&#xff0c;只好把资料罗列出来&#xff0c;留待以后总结&#xff1a; 1、Javascript的…

Citrix Synergy 2014 重要信息快速一览

今天的互联网、社交媒体的确强大&#xff0c;我们可以足不出户了解到9600公里&#xff08;北京到LA的距离&#xff09;之外的美国发生的事情。今天从Brain Madden大神那儿又扒到了一些经过提炼的关于Citrix Synergy 2014&#xff08;Citrix每年一度的大会&#xff09;的会议内容…

stm32 flash和sram

FLASH是用来存储程序的&#xff0c;SRAM是用来存储程序运行中的中间变量转载于:https://www.cnblogs.com/CodeWorkerLiMing/p/10984065.html

常见主机字节序

常见主机字节序1&#xff0e; Little endian&#xff1a;将低序字节存储在起始地址2&#xff0e; Big endian&#xff1a;将高序字节存储在起始地址LE little-endian最符合人的 思维的字节序地址低位存储值的低位地址高位存储值的高位怎么讲是最符合人的思维的字节序&#xff0…

Java项目:仿小米电子产品售卖商城系统(java+SpringBoot+Vue+MySQL+Redis+ElementUI)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 项目描述&#xff1a;这是一个基于SpringBootVue框架开发的仿小米电子产品售卖商城系统。首先&#xff0c;这是一个前后端分离的项目&#xff0c;代码简洁规范&#xff0c;注释说明详细。其次&#xff0c;这…

在js中使用createElement创建HTML对象和元素

1.创建链接 <script language"javascript"> var o document.body; //创建链接 function createA(url,text) { var a document.createElement("a"); a.href url; a.innerHTML text; a.style.color "red"; o.appendChild(a); …

Leetcode | 3Sum

Given an array S of n integers, are there elements a, b, c in S such that a b c 0? Find all unique triplets in the array which gives the sum of zero. Note:Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ c)The solution set …

玩转 JavaScript 面试:何为函数式编程?

函数式编程在 JavaScript 领域着实已经成为一个热门话题。就在几年前&#xff0c;很多 JavaScript 程序员甚至都不知道啥是函数式编程&#xff0c;但是就在近三年里我看到过的每一个大型应用的代码库中都包含了函数式编程思想的大规模使用。 函数式编程(缩写为 FP)是一种通过组…

正则表达式分类 区别

原文地址&#xff1a;http://www.cnblogs.com/chengmo/archive/2010/10/10/1847287.html 正则表达式&#xff1a;在计算机科学中&#xff0c;是指一个用来描述或者匹配一系列符合某个句法规则的字符串的单个字符串。在很多文本编辑器或其他工具里&#xff0c;正则表达式通常被用…

Java项目:嘟嘟校园一卡通系统(java+JSP+Servlet+html+css+JavaScript+JQuery+Ajax+mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 功能&#xff1a;卡管理&#xff0c;卡消费&#xff0c;卡充值&#xff0c;图书借阅&#xff0c;消费&#xff0c;记录&#xff0c;注销等等功能。 二、项目运行 环境配置&#xff1a; Jdk…

OC与C语言的区别

C语言是面向过程的编程语言&#xff0c;而OC则是面向对象的编程语言。面向对象:打个比方,就是你做一次菜,让老婆做个菜,吃饭,这就是面向对象,效率高面向过程,就是每一个细节:比如你要先把或开到合适的位置.然后还要洗菜 ,等油热了,才能开始炒菜,然后调料,...,起锅,到碗里,吃饭.…

Hutool之集合工具——CollectionUtil

为什么80%的码农都做不了架构师&#xff1f;>>> 集合工具 CollectionUtil 这个工具主要增加了对数组、集合类的操作。 1. join 方法 将集合转换为字符串&#xff0c;这个方法还是挺常用&#xff0c;是StrUtil.split的反方法。这个方法的参数支持各种类型对象的集合…

15:解决IntelliJ IDEA的乱码问题

1. -Dfile-encodingsUTF-8 &#xff0c;全局&#xff1a; 转载于:https://www.cnblogs.com/gzhbk/p/10991335.html

C++ 和C 语言混合代码导致的问题

C语言中操作字符串用C运行时函数&#xff1a;strtok, strcmp, strcpy等等&#xff0c;直接操作内存。在c引入的字符串操作类std:string &#xff0c;string类中必有一个私有成员&#xff0c;其是一个char*&#xff0c;用户记录从堆上分配内存的地址&#xff0c;其在构造时分配内…

SVN详细使用教程

SVN简介&#xff1a; 为什么要使用SVN&#xff1f; 程序员在编写程序的过程中&#xff0c;每个程序员都会生成很多不同的版本&#xff0c;这就需要程序员有效的管理代码&#xff0c;在需要的时候可以迅速&#xff0c;准确取出相应的版本。 Subversion是什么&#xff1f; 它是一…

Java项目:药店信息管理系统(java+SSM+JSP+layui+maven+mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 环境配置&#xff1a; Jdk1.8 Tomcat8.5 mysql Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09; 项目技术&#xff1a; JSP Spring SpringMVC MyBatis ht…

MongoDB简单操作

MongoDB简单操作 Hadoop核心技术厂商Cloudera将在2014/06推出hadoop Ecosystem与MongoDB的整合产品,届时MongoDB与ipmala及hbase,hive一起用; 开源linux领军企业RHEL也宣布RHEL将整合MongoDB用于简化用户账号管理与LDAP一起用; 数据仓库之MPP技术 领军者莫非 Vertica,exterdata…

Windows Presentation Foundation(介绍外连接)

Windows Presentation Foundation 2011/08/12更新&#xff1a;2010 年 12 月 Windows Presentation Foundation (WPF) 为开发人员提供了统一的编程模型&#xff0c;可用于构建合并了 UI、媒体和文档的丰富 Windows 智能客户端用户体验。 欢迎使用 WPF 了解 WPF&#xff1a; WP…

Linux中与进程终止相关的信号SIGTERM,SIGKILL,SIGINT

1. SIGTERM “kill pid” 会发送SIGTERM到进程pid. This is the termination signal sent by killcommand by default. 2. SIGINT 在终端中敲入interrupt key&#xff08;DELETE或ctrlc&#xff09;会产生SIGINT信号。这个信号会被发送到进程(inforeground proc…

Java项目:嘟嘟二手书商城系统(java+JSP+Springboot+maven+mysql+ThymeLeaf+FTP)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 功能&#xff1a; 主页显示商品&#xff1b; 所有二手书商品展示&#xff0c;可进行商品搜索&#xff1b; 点击商品进入商品详情页&#xff0c;具有立即购买和加入购物车功能&#xff0c;可增减…

SQL用法总结

1、创建数据库语句 create table persons(id INT NOT NULL AUTO_INCREMENT,lastname VARCHAR(255) NOT NULL,firstname VARCHAR(255) NOT NULL,PRIMARY KEY (ID)) DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; 2、创建数据库时&#xff0c;PK、NN、UQ、BIN、UN、…

[leetcode] Binary Tree Preorder Traversal

Given a binary tree, return the preorder traversal of its nodes values. For example:Given binary tree {1,#,2,3}, 1\2/3return [1,2,3]. Note: Recursive solution is trivial, could you do it iteratively? 给定一棵二叉树&#xff0c;使用非递归的方法进行先序遍历。…

error C2065: “M_PI”: 未声明的标识符

1.首先&#xff0c;程序中头文件的选择&#xff0c;要选择<math.h>头文件&#xff0c;在<cmath>文件中是没有对M_PI 的定义的&#xff08;现在的<cmath>中对M_PI好像已有定义&#xff09;。2.选择&#xff1a;项目——>”XXX属性"——>配置属性—…

区分HPUX是Itanium还是PA-RISC

转自&#xff1a;http://blog.csdn.net/nbzll0920/article/details/7961232 pa-risc的产品号以rp打头&#xff0c;itanium的产品号以rx打头 用model或者uname -a命令看一下就知道了 PS: Intel安腾处理器构建在IA-64&#xff08;Intel Architecture 64&#xff09;&#xff0c;…

Java项目:食品溯源系统(java+Springboot+Maven+mybatis+Vue+mysql+wd)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目运行 环境配置&#xff1a; Jdk1.8 Tomcat8.5 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术…

使用sqlite保存数据返回主键

/// <summary>/// 返回insert后的主键值/// </summary>/// <param name"SQLString"></param>/// <param name"para"></param>/// <returns></returns>public static int ExecuteSql(string SQLString, Li…

Pycharm初始创建项目和环境搭建(解决aconda库文件引入不全等问题)

1.新建工程 1&#xff0e;选择新建一个Pure Python项目&#xff0c;新建项目路径可以在Location处选择。 2.Project Interpreter部分是选择新建项目所依赖的python库&#xff0c;第一个选项会在项目中简历一个venv&#xff08;virtualenv&#xff09;目录&#xff0c;这里存放…