基于SpringBoot的阳光线上交友系统的设计与实现
随着科学技术和人类生活质量的不断发展,计算机技术已经应用到多个领域中,成为许多行业的经营工具。在当今时代,人们不仅需要生活物质上的满足,更渴望精神心理上的满足。但是,由于人们常常为了生活去奔波, 时间来人事更多的朋友,解释更多的同道中人,阳光线上交友系统应运而生。本系统可以为用户随机刷新新朋友,并且可以进行添加好友,如果对方同意,你们就可以深入了解对方,甚至成为良师益友。用户可以在无聊的时候登录该系统,快速交识新朋友。
本系统采用MVC设计模式进行开发,前端通过LayUI开源框架进行开发,后端利用SpringBoot框架进行开发,数据库采用MySQL,通过MyBatis将实体类与数据库表进行映射,安全框架采用Shiro,整体采用前后端分离。
本系统分为六大模块:登录模块、个人信息维护模块、寻找好友模块、我的地盘模块、我的钱包模块、充值人员模块。
【554】基于SpringBoot的阳光线上交友系统源码和论文
关键词:线上交友;SpringBoot;Shiro
Design and Implementation of Sunshine Online Make Friends System Based on SpringBoot
Abstract
With the continuous development of science and technology and the quality of human life, computer technology has been applied to many fields and has become a management tool for many industries。 In today's era, people not only need material satisfaction in life, but also long for spiritual and psychological satisfaction。 However, because people often run around for life, and have time to recruit more friends and explain more like-minded people, the Sunshine Online Dating System came into being。 This system can randomly refresh new friends for users, and can add friends。 If the other party agrees, you can get to know each other deeply, and even become a good teacher and friend。 Users can log into the system when they are bored and make new friends quickly。
The system adopts the MVC design pattern for development, the front-end is developed through the LayUI open source framework, the back-end is developed using the SpringBoot framework, the database adopts MySQL, the entity classes and database tables are mapped through MyBatis, the security framework adopts Shiro, and the overall front-end and back-end separation is adopted.
This system is divided into six modules: login module, personal information maintenance module, friend finding module, my site module, my wallet module, and recharge personnel module.
Keywords: Make Friends;SpringBoot;Shiro
package com.zh.yangguang.web;
import com.zh.yangguang.mapper.UserMapper;
import com.zh.yangguang.pojo.Friend;
import com.zh.yangguang.pojo.User;
import com.zh.yangguang.pojo.UserDetail;
import com.zh.yangguang.server.*;
import com.zh.yangguang.utile.ResultUtil;
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 org.springframework.web.multipart.MultipartFile;
import org.springframework.web.util.WebUtils;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
@Controller
public class UserDetailController {
@Autowired
private UserDetailService userDetailService;
@Autowired
private AreaService areaService;
@Autowired
private UserService userService;
@Autowired
private UserMapper userMapper;
@Autowired
private FriendService friendService;
@Autowired
private RechargeService rechargeService;
@RequestMapping("/uploadImage")
@ResponseBody
public ResultUtil uploadImage(MultipartFile file, HttpServletRequest req) throws IOException {
String filename=System.currentTimeMillis()+file.getOriginalFilename();
String path = WebUtils.getRealPath(req.getSession().getServletContext(),
"/image/");
File f=new File(path+ filename);
if( !f.getParentFile().exists()) {
// 如果目标文件所在的目录不存在,则创建父目录
f.getParentFile().mkdirs();
}
file.transferTo(f);
ResultUtil r=ResultUtil.ok();
r.setData(filename);
return r;
}
@RequestMapping("initUserDetail")
@ResponseBody
public ResultUtil insertUserDetail(UserDetail userDetail, HttpServletRequest req){
User u=(User)req.getSession().getAttribute("loginUser");
userDetail.setUpdId(u.getId());
userDetail.setUpdTime(new Date());
req.getSession().setAttribute("loginUserDetail",userDetail);
req.getSession().setAttribute("adr1",areaService.findById(userDetail.getAdr1()));
req.getSession().setAttribute("adr2",areaService.findById(userDetail.getAdr2()));
req.getSession().setAttribute("adr",areaService.findById(userDetail.getAdr()));
if(u.getStatus()!=-1){
userDetailService.updUserDetail(userDetail);
return ResultUtil.ok("修改");
}else{
int n=userDetailService.insertUserDetail(userDetail);
userService.setStatusToOne(u.getId());
User user=userMapper.selectByPrimaryKey(userDetail.getId());
req.getSession().setAttribute("loginUser",user);
return ResultUtil.ok("跳转");
}
}
@RequestMapping("getuserList")
@ResponseBody
public ResultUtil getuserList(String content,Integer adr1,Integer sex,Integer adr2,Integer adr3,String page,String limit,HttpServletRequest req){
Integer adr;
if(adr3!=null){
adr=adr3;
}
else if(adr2!=null){
adr=adr2/100;
}
else if(adr3!=null){
adr=adr2/10000;
}else{
adr=null;
}
req.setAttribute("content",content);
List<User> list=userDetailService.findAll(content,adr,sex,(Integer.parseInt(page)-1)*Integer.parseInt(limit), Integer.parseInt(limit));
Integer n=userDetailService.UserCount(content,adr,sex);
ResultUtil ru=new ResultUtil().ok();
ru.setData(list);
ru.setCount(n);
return ru;
}
@RequestMapping("updsome")
@ResponseBody
public ResultUtil updsome(UserDetail userDetail){
int n= userDetailService.updsome(userDetail);
if(n>0){
return ResultUtil.ok();
}else{
return ResultUtil.error();
}
}
@RequestMapping("addfrient")
@ResponseBody
public ResultUtil addfrient(String id,HttpServletRequest req){
User u=(User)req.getSession().getAttribute("loginUser");
List<Friend> list=friendService.findFriendByTowId(id,u.getId());
if(list.size()>0){
return ResultUtil.error("你已申请过,或你们已经是好友");
}
User user=userMapper.findUserByUsername(u.getUsername());
UserDetail userDetail=userDetailService.findByID(user.getId());
if(user.getMoney()<0.2){
return ResultUtil.error("余额不足");
}else{
rechargeService.addRecharge(user.getId(),userDetail.getPickname(),-0.2);
userService.loseTwoMoney(user.getId());
friendService.addfriend(user.getId(),id);
return ResultUtil.ok();
}
}
@RequestMapping("getrandomList")
@ResponseBody
public ResultUtil getrandomList(HttpServletRequest req){
User user=(User)req.getSession().getAttribute("loginUser");
List<UserDetail> list=userDetailService.findNotSelf(user.getId());
int count=list.size();
Random r=new Random();
List<UserDetail> l=new ArrayList();
for(int i=0;i<5;i++){
l.add(list.get(r.nextInt(count)));
}
ResultUtil ru=new ResultUtil().ok();
ru.setData(l);
ru.setCount(5);
return ru;
}
@RequestMapping("/userdetailinfo")
public String touserdetailinfo(HttpServletRequest req){
return "user/userDetail";
}
@RequestMapping("editUser")
public String editUser(String id ,HttpServletRequest req){
req.setAttribute("user",userDetailService.findByID(id));
return "user/editUser";
}
@RequestMapping("randomfriend")
public String randomuser(HttpServletRequest req){
return "user/randomUser";
}
}
package com.zh.yangguang.web;
import com.zh.yangguang.mapper.UserMapper;
import com.zh.yangguang.pojo.Recharge;
import com.zh.yangguang.pojo.User;
import com.zh.yangguang.pojo.UserDetail;
import com.zh.yangguang.server.RechargeService;
import com.zh.yangguang.server.UserDetailService;
import com.zh.yangguang.server.UserService;
import com.zh.yangguang.utile.ResultUtil;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
@Controller
public class RachargeController {
@Autowired
private RechargeService rechargeService;
@Autowired
private UserMapper userMapper;
@RequestMapping("getrechargelist")
@ResponseBody
private ResultUtil rechargelist(String content, Integer type, String page, String limit, HttpServletRequest req){
User user=(User)req.getSession().getAttribute("loginUser");
String id=null;
if("2".equals(user.getType())){
id=user.getId();
}
List<Recharge> list=rechargeService.rechargelist(id,content,type,(Integer.parseInt(page)-1)*Integer.parseInt(limit), Integer.parseInt(limit));
int n=rechargeService.rechargelistCount(id,content,type);
ResultUtil ru=new ResultUtil().ok();
ru.setData(list);
ru.setCount(n);
return ru;
}
@RequestMapping("addmoney")
@ResponseBody
private ResultUtil addmoney(Recharge recharge){
User user=userMapper.findUserByUsername(recharge.getUsername());
if(user==null){
return ResultUtil.error("用户不存在");
}
recharge.setId(user.getId());
recharge.setTime(new Date());
recharge.setStatus(1);
rechargeService.addmoney(recharge);
userMapper.addmoney(user.getId(),recharge.getMoney());
return ResultUtil.ok();
}
@RequestMapping("delRecharge")
@ResponseBody
public ResultUtil delRecharge(String id){
return rechargeService.delRecharge(id);
}
@RequestMapping("myrecharge")
private String myrecharge(){
return "recharge/rechargeList";
}
@RequestMapping("recharge")
private String recharge(){
return "recharge/recharge";
}
@RequestMapping("torecharge")
private String torecharge(){
return "recharge/torecharge";
}
}