博主介绍:5年java开发经验,专注Java开发、定制、远程、指导等,csdn特邀作者、专注于Java技术领域
作者主页 超级帅帅吴
Java项目精品实战案例《500套》
欢迎点赞 收藏 ⭐留言
文末获取源码联系方式
目录
- 主要功能模块设计
- 主要技术:
- 主要功能实现前端:
- 工资平台首页:
- 登录注册管理:
- 支出管理:
- 收入管理:
- 报表统计:
- 部分关键代码展示:
- 登录模块:
- 配置模块:
- 主要表设计:
- 用户表:
- 权限表:
- 收支信息表:
主要功能模块设计
登录注册、用户管理、支出管理、收入管理、统计报表、系统管理、角色管理等
主要技术:
Java、springboot、mybatis、mysql、jquery、layui、JavaScript、html、css、jsp、log4j等一些常见的基本技术。
主要功能实现前端:
运行项目后 输入http://localhost:8080/boot_famcwmanage 访问系统 页面
工资平台首页:
登录注册管理:
支出管理:
收入管理:
报表统计:
部分关键代码展示:
登录模块:
package com.example.cwgl.controller;
import com.example.cwgl.entity.Privilege;
import com.example.cwgl.entity.Role;
import com.example.cwgl.entity.UserInfo;
import com.example.cwgl.service.PrivilegeService;
import com.example.cwgl.service.UserInfoService;
import com.example.cwgl.utils.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@Controller
public class UserInfoController {
@Resource
private UserInfoService userInfoService;
@Resource
private PrivilegeService privilegeService;
@RequestMapping(value = {"/", "login.html"})
public String toLogin(HttpServletRequest request, HttpServletResponse response){
HttpSession session = request.getSession();
if(session.getAttribute(Config.CURRENT_USERNAME)==null){
return "login";
}else {
try {
response.sendRedirect("/boot_famcwmanage/pages/index");
} catch (IOException e) {
e.printStackTrace();
return "login";
}
return null;
}
}
@RequestMapping(value = "/login.do")
@ResponseBody
public Result getUserInfo(UserInfo userInfo, HttpServletRequest request, HttpServletResponse response){
boolean userIsExisted = userInfoService.userIsExisted(userInfo);
System.out.println(userIsExisted + " - " + request.getHeader("token"));
userInfo = getUserInfo(userInfo);
if("client".equals(request.getHeader("token")) && !userIsExisted){
return ResultUtil.success(-1);
}
if (userIsExisted && userInfo == null){
return ResultUtil.unSuccess("用户名或密码错误!");
}else {
userInfo = setSessionUserInfo(userInfo,request.getSession());
setCookieUser(request,response);
return ResultUtil.success("登录成功", userInfo);
}
}
@RequestMapping("/users/getUsersByWhere/{pageNo}/{pageSize}")
public @ResponseBody Result getUsersByWhere(UserInfo userInfo, @PathVariable int pageNo, @PathVariable int pageSize, HttpSession session){
if ("".equals(userInfo.getHouseid())){
userInfo.setHouseid(null);
}
if (userInfo.getRoleid() == -1){
userInfo.setRoleid(Config.getSessionUser(session).getRoleid());
}
Utils.log(userInfo.toString());
PageModel model = new PageModel<>(pageNo,userInfo);
model.setPageSize(pageSize);
return userInfoService.getUsersByWhere(model);
}
@RequestMapping("/user/add")
public @ResponseBody Result addUser(UserInfo userInfo){
System.out.println(userInfo);
try {
int num = userInfoService.add(userInfo);
if(num>0){
return ResultUtil.success();
}else {
return ResultUtil.unSuccess();
}
}catch (Exception e){
return ResultUtil.error(e);
}
}
@RequestMapping("/user/update")
public @ResponseBody Result updateUser(UserInfo userInfo){
try {
int num = userInfoService.update(userInfo);
if(num>0){
return ResultUtil.success();
}else {
return ResultUtil.unSuccess();
}
}catch (Exception e){
return ResultUtil.error(e);
}
}
@RequestMapping("/user/del/{id}")
public @ResponseBody Result deleteUser(@PathVariable String id){
try {
int num = userInfoService.delete(id);
if(num>0){
return ResultUtil.success();
}else {
return ResultUtil.unSuccess();
}
}catch (Exception e){
return ResultUtil.error(e);
}
}
@RequestMapping("/getSessionUser")
@ResponseBody
public UserInfo getSessionUser(HttpSession session){
UserInfo sessionUser = (UserInfo) session.getAttribute(Config.CURRENT_USERNAME);
sessionUser.setPassword(null);
return sessionUser;
}
@RequestMapping("/logout")
public String logout(HttpServletRequest request, HttpServletResponse response){
delCookieUser(request, response);
request.getSession().removeAttribute(Config.CURRENT_USERNAME);
return "login";
}
@RequestMapping("/getAllRoles")
public @ResponseBody Result<Role> getAllRoles(){
try {
List<Role> roles = userInfoService.getAllRoles();
if (roles.size()>0){
return ResultUtil.success(roles);
}else {
return ResultUtil.unSuccess();
}
}catch (Exception e){
return ResultUtil.error(e);
}
}
@RequestMapping("/role/add")
public @ResponseBody Result addRole(Role role){
try {
int num = userInfoService.addRole(role);
if(num>0){
privilegeService.addDefaultPrivilegesWhenAddRole(role.getRoleid().toString());
return ResultUtil.success();
}else {
return ResultUtil.unSuccess();
}
}catch (Exception e){
return ResultUtil.error(e);
}
}
@RequestMapping("/role/update")
public @ResponseBody Result updateRole(Role role){
try {
int num = userInfoService.updateRole(role);
if(num>0){
return ResultUtil.success();
}else {
return ResultUtil.unSuccess();
}
}catch (Exception e){
return ResultUtil.error(e);
}
}
@RequestMapping("/role/del/{roleid}")
public @ResponseBody Result deleteRole(@PathVariable String roleid){
try {
privilegeService.delPrivilegesWenDelRole(roleid);
int num = userInfoService.deleteRole(roleid);
if(num>0){
return ResultUtil.success();
}else {
privilegeService.addDefaultPrivilegesWhenAddRole(roleid);
return ResultUtil.unSuccess();
}
}catch (Exception e){
return ResultUtil.error(e);
}
}
@RequestMapping("/getRole/{id}")
public @ResponseBody Result getRoleById(@PathVariable String id){
try {
Role role = userInfoService.getRoleById(id);
if(role != null){
return ResultUtil.success(role);
}else {
return ResultUtil.unSuccess();
}
}catch (Exception e){
return ResultUtil.error(e);
}
}
private void setCookieUser(HttpServletRequest request, HttpServletResponse response){
UserInfo user = getSessionUser(request.getSession());
Cookie cookie = new Cookie(Config.CURRENT_USERNAME,user.getUsername()+"_"+user.getId());
cookie.setMaxAge(60*60*24*7);
response.addCookie(cookie);
}
private void delCookieUser(HttpServletRequest request, HttpServletResponse response){
UserInfo user = getSessionUser(request.getSession());
Cookie cookie = new Cookie(Config.CURRENT_USERNAME,user.getUsername()+"_"+user.getId());
cookie.setMaxAge(-1);
response.addCookie(cookie);
}
public UserInfo setSessionUserInfo(UserInfo userInfo, HttpSession session){
List<Privilege> privileges = privilegeService.getPrivilegeByRoleid(userInfo.getRoleid());
userInfo.setPrivileges(privileges);
session.setAttribute(Config.CURRENT_USERNAME,userInfo);
return userInfo;
}
public UserInfo getUserInfo(UserInfo userInfo){
return userInfoService.getUserInfo(userInfo);
}
}
配置模块:
server:
port: 8080
servlet:
context-path: /boot_famcwmanage
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3307/boot_famcwmanage?autoReconnect=true&useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: 123456
jpa:
database: mysql
mvc:
static-path-pattern: /static
主要表设计:
用户表:
CREATE TABLE `user` (
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
`username` varchar(255) DEFAULT NULL COMMENT '账号',
`password` varchar(255) DEFAULT NULL COMMENT '密码',
`realname` varchar(255) DEFAULT NULL COMMENT '真实姓名',
`roleid` int NOT NULL DEFAULT '3' COMMENT '角色编号',
`houseid` int DEFAULT NULL COMMENT '所属家庭编号',
`photo` varchar(255) DEFAULT NULL COMMENT '用户头像',
PRIMARY KEY (`id`) USING BTREE,
KEY `houseid` (`houseid`) USING BTREE,
KEY `roleid` (`roleid`) USING BTREE,
CONSTRAINT `user_ibfk_2` FOREIGN KEY (`houseid`) REFERENCES `house` (`id`),
CONSTRAINT `user_ibfk_3` FOREIGN KEY (`roleid`) REFERENCES `role` (`roleid`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
权限表:
CREATE TABLE `privilege` (
`ID` int NOT NULL AUTO_INCREMENT COMMENT '主键',
`privilegeNumber` varchar(80) DEFAULT NULL COMMENT '权限编号',
`privilegeName` varchar(80) DEFAULT NULL COMMENT '权限名称',
`privilegeTipflag` char(4) DEFAULT NULL COMMENT '菜单级别',
`privilegeTypeflag` char(4) DEFAULT NULL COMMENT '1启用 0禁用',
`privilegeUrl` varchar(255) DEFAULT NULL COMMENT '权限URL',
`icon` varchar(20) DEFAULT NULL COMMENT '图标',
PRIMARY KEY (`ID`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=75 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
收支信息表:
CREATE TABLE `bill` (
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
`title` varchar(255) DEFAULT NULL,
`userid` int DEFAULT NULL COMMENT '用户id',
`money` float(10,2) DEFAULT NULL COMMENT '金额',
`typeid` int NOT NULL COMMENT '类型 1 收入 2 支出',
`remark` varchar(255) DEFAULT NULL COMMENT '备注',
`paywayid` int DEFAULT NULL COMMENT '支付方式',
`time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '交易时间',
PRIMARY KEY (`id`) USING BTREE,
KEY `userid` (`userid`) USING BTREE,
KEY `type` (`typeid`) USING BTREE,
KEY `payway` (`paywayid`) USING BTREE,
CONSTRAINT `bill_ibfk_2` FOREIGN KEY (`typeid`) REFERENCES `type` (`id`),
CONSTRAINT `bill_ibfk_3` FOREIGN KEY (`paywayid`) REFERENCES `payway` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=195 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
获取源码:
总体来说这个项目功能相对还是比较简单优秀的、适合初学者作为课程设计和毕业设计参考
🍅 查看下方微信号获取联系方式 📝
🚀🚀🚀精彩系列推荐
Java毕设项目精品实战案例《500套》
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)