博主主页:Java旅途
简介:分享计算机知识、学习路线、系统源码及教程
文末获取源码
一、项目介绍
婚恋网站是由SpringBoot+Mybatis开发的,功能详细,满足婚恋网的基本要求。
主要功能如下:
- 登录注册
- 用户浏览
- 用户搜索
- 成功故事
- 发表祝福
- 故事点赞
- 个人资料完善
- 金币模拟充值
- 关注用户
- 私信聊天
- …
二、技术框架
- 后端:SpringBoot,Mybatis
- 前端:jquery
三、安装教程
-
用idea打开项目
-
在idea中配置jdk环境
-
配置maven环境并下载依赖
-
新建数据库,导入数据库文件
-
在application.yml文件中将数据库账号密码改成自己本地的
-
启动运行。账号密码列表
abc@qq.com / 123456 xtt@qq.com / 123456 cf@qq.com / 123456 wx@qq.com / 123456 pyf@qq.com / 123456 zh@qq.com / 123456
四、项目截图
五、相关代码
IndexController
package com.hpe.findlover.contoller.front;import com.github.pagehelper.PageHelper;
import com.hpe.findlover.model.*;
import com.hpe.findlover.service.*;
import com.hpe.findlover.util.Constant;
import com.hpe.findlover.util.LoverUtil;
import com.hpe.findlover.util.SessionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;/****/
@Controller
public class IndexController {@Autowiredprivate UserAssetService userAssetService;@Autowiredprivate UserPickService userPickService;@Autowiredprivate DictService dictService;@Autowiredprivate UserService userService;@Autowiredprivate VisitTraceService visitTraceService;@Autowiredprivate SuccessStoryService successStoryService;private Logger logger = LogManager.getLogger(IndexController.class);/**** @Describtion: 跳转到是首页,需要给首页传递的数据有* 1、用户信息,用于显示用户资料* 2、用户择偶条件,用于推荐每日情缘* 3、光荣脱单榜* 4、成功故事* 5、谁看过我**/@GetMapping(value = {"","index"})public String index(Model model, HttpServletRequest request) throws Exception {logger.debug("User Subject: "+ SecurityUtils.getSubject().getPrincipal().toString());//获取光荣脱单榜Map<UserBasic, Integer> vipNotSingles = successStoryService.selectVipNotSingle();//1.用户信息,基本信息可以从session中直接获取,消费信息需要我们查询数据库UserBasic user = (UserBasic)request.getSession().getAttribute("user");user.setAge(LoverUtil.getAge(user.getBirthday()));logger.debug("user:"+user);UserAsset userAsset = userAssetService.selectByPrimaryKey(user.getId());logger.debug("userAsset:"+userAsset);//剩余时间计算int vipDate=0, starDate=0,asset=0;if (userAsset!=null){if (userAsset.getVipDeadline()!=null){vipDate = LoverUtil.getDiffOfDays(userAsset.getVipDeadline());}if (userAsset.getStarDeadline()!=null){starDate = LoverUtil.getDiffOfDays(userAsset.getStarDeadline());}if (userAsset.getAsset()!=null){asset= userAsset.getAsset();}}logger.debug("vipDate="+vipDate+"....starDate="+starDate+".....asset="+asset);model.addAttribute("vipDate",vipDate);model.addAttribute("starDate",starDate);model.addAttribute("asset",asset);//2、用户择偶条件,用于推荐每日情缘UserPick userPick = userPickService.selectByPrimaryKey(user.getId());List<UserBasic> userBasicList = getDayLovers(userPick,user);model.addAttribute("dayLover",userBasicList);//职业List<Dict> jobList = dictService.selectDictByType("job");model.addAttribute("userPick",userPick);model.addAttribute("jobList",jobList);model.addAttribute("vipNotSingles",vipNotSingles);logger.debug(vipNotSingles);// * 5、谁看过我PageHelper.startPage(1,5,"visit_time desc");List<VisitTrace> visitTraces = visitTraceService.selectIndexVisitTracer(user.getId());model.addAttribute("visitTraces",visitTraces);// * 4、成功故事PageHelper.startPage(1,5,"success_time desc");List<SuccessStory> successStories = successStoryService.selectAllByStatus();for (SuccessStory success : successStories) {success.setUserLeft(userService.selectByPrimaryKey(success.getLeftUser()));success.setUserRight(userService.selectByPrimaryKey(success.getRightUser()));}model.addAttribute("successStories",successStories);return "front/index";}@GetMapping("index/initSearch")@ResponseBodypublic UserPick initSearch(HttpServletRequest request){UserBasic user = (UserBasic)request.getSession().getAttribute("user");return userPickService.selectByPrimaryKey(user.getId());}@PostMapping("index/getSearchUser")@ResponseBodypublic List<UserBasic> getSearchUser(UserPick userPick,HttpServletRequest request){UserBasic user = SessionUtils.getSessionAttr("user",UserBasic.class);return getDayLovers(userPick,user);}/*** 更具用户择偶条件选出16个每日情缘,* * 如果择偶条件对应的人数不够,则从所有性取向对应用户随机选取凑够16个* * @param userPick* @return*/private List<UserBasic> getDayLovers(UserPick userPick, UserBasic user){userPick.setId(user.getId());logger.debug("userPick..."+userPick);List<UserBasic> userBasicList = userService.selectUserByUserPick(userPick);LoverUtil.formatUserInfo(userBasicList);if (userBasicList.size()> Constant.INDEX_SHOW_USER_NUMBER){logger.debug("根据择偶条件选出来的用户大于16,需要随机选取");return LoverUtil.getRandomUser(userBasicList,Constant.INDEX_SHOW_USER_NUMBER);}else {logger.debug("根据择偶条件选出来的用户小于16,需要从数据库随机获取");int size = Constant.INDEX_SHOW_USER_NUMBER-userBasicList.size();List<UserBasic> userBasics = userService.selectUserBySexualAndWorkProvince(user.getId(),userPick.getSex(),user.getWorkplace().substring(0,2));if (userBasics==null||userBasics.size()<size){logger.debug("根据性取向和工作最地选出来的用户小于16,只选取性取向对应的用户");userBasics =userService.selectUserBySexualAndWorkProvince(user.getId(),userPick.getSex(),null);}LoverUtil.formatUserInfo(userBasics);List<UserBasic> allUsers = LoverUtil.getRandomUser(userBasics,size);userBasicList.addAll(allUsers);userBasicList.forEach(logger::debug);return userBasicList;}}}
AdminController
package com.hpe.findlover.contoller.back;import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hpe.findlover.model.Admin;
import com.hpe.findlover.service.AdminRoleService;
import com.hpe.findlover.service.AdminService;
import com.hpe.findlover.service.RoleService;
import com.hpe.findlover.token.CustomToken;
import com.hpe.findlover.util.Identity;
import com.hpe.findlover.util.LoverUtil;
import com.hpe.findlover.util.SessionUtils;
import com.hpe.findlover.util.ShiroHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.security.InvalidParameterException;
import java.util.Arrays;
import java.util.Date;@Controller
@RequestMapping("admin")
public class AdminController {private Logger logger = LogManager.getLogger(AdminController.class);private final AdminService adminService;private final RoleService roleService;private final AdminRoleService adminRoleService;@Autowiredpublic AdminController(AdminService adminService, RoleService roleService, AdminRoleService adminRoleService) {this.adminService = adminService;this.roleService = roleService;this.adminRoleService = adminRoleService;}@GetMapping(value = {"", "index"})public String index() {return "back/index";}@GetMapping("logout")public String logout() {SecurityUtils.getSubject().logout();SecurityUtils.getSubject().getSession().removeAttribute("admin");return "redirect:login";}@GetMapping("login")public String login() {return "back/login";}@PostMapping("login")public String login(String username, String password, HttpSession session, RedirectAttributes redirectAttributes) {ShiroHelper.flushSession();CustomToken token = new CustomToken(username, password, Identity.ADMIN);try {SecurityUtils.getSubject().login(token);if (SecurityUtils.getSubject().isAuthenticated()) {Admin admin = new Admin();admin.setUsername(token.getUsername());admin = adminService.selectOne(admin);admin.setLastLogin(new Date());adminService.updateByPrimaryKey(admin);session.setAttribute("admin", admin);return "redirect:index";} else {return "redirect:login";}} catch (UnknownAccountException uae) {redirectAttributes.addAttribute("message", "用户名不存在");} catch (IncorrectCredentialsException ice) {redirectAttributes.addAttribute("message", "密码不正确");}return "redirect:login";}@GetMapping("admins/page")@RequiresRoles("admin")public String listPage(@RequestParam String type, Model model) {if ("list".equals(type)) {return "back/admin/admin_list";} else if ("add".equals(type)) {model.addAttribute("roles", roleService.selectAll());return "back/admin/admin_add";}throw new InvalidParameterException("没有" + type + "对应的页面。");}@GetMapping("admins")@RequiresRoles("admin")@ResponseBodypublic PageInfo<Admin> list(@RequestParam int pageNum, @RequestParam int pageSize, @RequestParam String keyword, @RequestParam String column) {PageHelper.startPage(pageNum, pageSize);return new PageInfo<>(adminService.selectByKeyword("%" + keyword + "%", column));}@GetMapping("admin_roles")@RequiresRoles("admin")@ResponseBodypublic JSONObject roleList(@RequestParam int adminId) {JSONObject result = new JSONObject();JSONArray arr = new JSONArray();roleService.selectAllByAdminId(adminId).forEach(v -> arr.add(v.getId()));result.put("adminRolesId", arr);result.put("roles", roleService.selectAll());return result;}@PostMapping("admin_roles")@RequiresRoles("admin")@ResponseBodypublic boolean updateAdminRole(@RequestParam("roleIds[]") int[] roleIds, @RequestParam int adminId) {return adminRoleService.updateAdminRole(roleIds, adminId);}@PostMapping("admins")@RequiresRoles("admin")public String addAdmin(Admin admin, int[] rid) {adminService.insert(admin, rid);return "back/admin/admin_list";}@GetMapping("admins/check")@RequiresRoles("admin")@ResponseBodypublic JSONObject usernameIsExists(@RequestParam String username) {Admin vo = new Admin();vo.setUsername(username);JSONObject obj = new JSONObject();if (adminService.selectOne(vo) == null) {obj.put("ok", "该用户名可用");} else {obj.put("error", "该用户名已存在,不能使用!");}return obj;}@GetMapping("admins/pwdcheck")@RequiresRoles("admin")@ResponseBodypublic boolean pwdCheck(Admin admin) {admin.setId(SessionUtils.getSessionAttr("admin", Admin.class).getId());admin.setPassword(LoverUtil.getMd5Password(admin.getPassword(), SessionUtils.getSessionAttr("admin", Admin.class).getUsername()));logger.debug("修改密码Admin:" + admin);return adminService.selectOne(admin) != null;}@PutMapping("admins")@RequiresRoles("admin")@ResponseBodypublic boolean updatePwd(Admin admin) {admin.setId(SessionUtils.getSessionAttr("admin", Admin.class).getId());admin.setPassword(LoverUtil.getMd5Password(admin.getPassword(), SessionUtils.getSessionAttr("admin", Admin.class).getUsername()));return adminService.updateByPrimaryKeySelective(admin);}@GetMapping("right")public String right(){return "back/common/right";}}
大家点赞、收藏、关注、评论啦 、👇🏻点开下方卡片👇🏻关注后回复 105