Java毕业设计实战之财务预算管理系统的实现
更新时间:2022年2月5日 20:31 点击:214 作者:qq_1334611189
一、项目简述
功能包括:实现公司对项目的管理。
二、项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等
用户信息控制层:
/** * 用户信息控制层 */ @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("/pages/index"); } catch (IOException e) { e.printStackTrace(); return "login"; } return null; } } // @RequestMapping(value = "/login.do",method = RequestMethod.POST) @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 { //将用户信息存入session userInfo = setSessionUserInfo(userInfo,request.getSession()); //将当前用户信息存入cookie 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); } } /** * 登录时将用户信息加入cookie中 * @param response */ private void setCookieUser(HttpServletRequest request, HttpServletResponse response){ UserInfo user = getSessionUser(request.getSession()); Cookie cookie = new Cookie(Config.CURRENT_USERNAME,user.getUsername()+"_"+user.getId()); //cookie 保存7天 cookie.setMaxAge(60*60*24*7); response.addCookie(cookie); } /** * 注销时删除cookie信息 * @param request * @param response */ 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); } /** * 通过用户信息获取用户权限信息,并存入session中 * @param userInfo * @param session * @return */ 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); } }
数据图形展示:
@RestController @RequestMapping("/bills") public class BillController { @Resource private BillService billService; /** * 适用于统计图 * @param bill * @return */ @RequestMapping("/getBillsToChart") public Result<Bill> findByWhereNoPage(Bill bill, HttpSession session){ bill = getHouseBill(bill,session); return billService.findByWhereNoPage(bill); } @RequestMapping("/getBillsByWhere/{type}/{pageNo}/{pageSize}") public Result<Bill> getBillsByWhere(Bill bill,@PathVariable String type, @PathVariable int pageNo, @PathVariable int pageSize, HttpSession session){ if("-1".equals(bill.getPayway())){ bill.setPayway(null); } bill.setType(type); bill = getHouseBill(bill,session); System.out.println(bill); PageModel model = new PageModel<>(pageNo,bill); model.setPageSize(pageSize); return billService.findByWhere(model); } @RequestMapping("/getBillsByUserid/{userid}/{pageNo}/{pageSize}/{year}/{month}") public Result getBillsByUserid(@PathVariable Integer userid, @PathVariable int pageNo, @PathVariable int pageSize, @PathVariable int year, @PathVariable int month){ Bill bill = new Bill(); bill.setUserid(userid); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); bill.setStartTime(year+"-0"+month+"-01"); try { Date date = sdf.parse(year+"-0"+(month+1)+"-01"); date.setDate(date.getDate()-1); bill.setEndTime(sdf.format(date)); } catch (ParseException e) { e.printStackTrace(); } PageModel model = new PageModel<>(pageNo,bill); model.setPageSize(pageSize); Result result = billService.findByWhere(model); List<Map<String,String>> r = billService.getMonthlyInfo(model); Map<String,String> map = new HashMap<>(); for (Map<String,String> m: r) { map.put(m.get("typeid"),String.format("%.2f",m.get("sum(money)"))); } result.setData(map); return result; } private Bill getHouseBill(Bill bill, HttpSession session) { UserInfo currentUser = Config.getSessionUser(session); //当登录用户为家主时,查询默认查询全家账单情况 //当登录用户为普通用户时,仅查询当前用户的账单 if (currentUser.getRoleid() == 2){ bill.setHouseid(currentUser.getHouseid()); }else if (currentUser.getRoleid() == 3){ bill.setUserid(currentUser.getId()); } return bill; } @RequestMapping(value = "/addBill",method = RequestMethod.POST) public Result add(Bill bill, HttpSession session){ if (Config.getSessionUser(session)!=null){ bill.setUserid(Config.getSessionUser(session).getId()); } Utils.log(bill.toString()); try { int num = billService.add(bill); if(num>0){ int billid = bill.getId(); bill = new Bill(); bill.setId(billid); return ResultUtil.success("记账成功!",billService.findByWhereNoPage(bill)); // return ResultUtil.success("记账成功!",bill); }else { return ResultUtil.unSuccess(); } }catch (Exception e){ return ResultUtil.error(e); } } @RequestMapping("/updateBill") public Result update(Bill bill, HttpSession session){ if (Config.getSessionUser(session)!=null){ bill.setUserid(Config.getSessionUser(session).getId()); } Utils.log(bill.toString()); try { int num = billService.update(bill); if(num>0){ return ResultUtil.success("修改成功!",null); }else { return ResultUtil.unSuccess(); } }catch (Exception e){ return ResultUtil.error(e); } } @RequestMapping("/delBill") public Result del(int id){ try { int num = billService.del(id); if(num>0){ return ResultUtil.success("删除成功!",null); }else { return ResultUtil.unSuccess(); } }catch (Exception e){ return ResultUtil.error(e); } } @RequestMapping("/getPayways") public Result<Payway> getAllPayways(){ try { List<Payway> payways = billService.getAllPayways(); if (payways!=null && payways.size()>0){ return ResultUtil.success(payways); }else { return ResultUtil.unSuccess(); } } catch (Exception e) { return ResultUtil.error(e); } } }
用户信息mapper类:
@Repository public interface UserInfoMapper { /** * 获取单个用户信息,可用于: * 1.登录 * 2.通过用户某一部分信息获取用户完整信息 * @param userInfo * @return */ UserInfo getUserInfo(UserInfo userInfo); /** * 注册 * @param userInfo * @return */ int addUser(UserInfo userInfo); /** * 通过username判断该用户是否存在 * @param userInfo * @return */ int userIsExisted(UserInfo userInfo); /** * 通过条件获取符合条件的优化信息 -- 分页 * @param model * @return */ List<UserInfo> getUsersByWhere(PageModel<UserInfo> model); int getToatlByWhere(PageModel<UserInfo> model); int add(UserInfo userInfo); int update(UserInfo userInfo); int delete(String id); List<Role> getAllRoles(); int addRole(Role role); int updateRole(Role role); int deleteRole(String id); Role getRoleById(String id); int addHouseId(House house); }
到此这篇关于Java毕业设计实战之财务预算管理系统的实现的文章就介绍到这了,更多相关Java 财务预算管理内容请搜索猪先飞以前的文章或继续浏览下面的相关文章希望大家以后多多支持猪先飞!
原文出处:https://blog.csdn.net/m0_59687645/article/details/122209022
相关文章
- 这篇文章主要介绍了如何利用java语言实现经典《复杂迷宫》游戏,文中采用了swing技术进行了界面化处理,感兴趣的小伙伴可以动手试一试...2022-02-01
java 运行报错has been compiled by a more recent version of the Java Runtime
java 运行报错has been compiled by a more recent version of the Java Runtime (class file version 54.0)...2021-04-01- 这篇文章主要介绍了在java中获取List集合中最大的日期时间操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-08-15
- 这篇文章主要介绍了教你怎么用Java获取国家法定节假日,文中有非常详细的代码示例,对正在学习java的小伙伴们有非常好的帮助,需要的朋友可以参考下...2021-04-23
- 这篇文章主要介绍了Java如何发起http请求的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-31
- 说起C#和Java这两门语言(语法,数据类型 等),个人以为,大概有90%以上的相似,甚至可以认为几乎一样。但是在工作中,我也发现了一些细微的差别...2020-06-25
- 这篇文章主要介绍了解决Java处理HTTP请求超时的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-29
- 这篇文章主要介绍了java 判断两个时间段是否重叠的案例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-08-15
java 画pdf用itext调整表格宽度、自定义各个列宽的方法
这篇文章主要介绍了java 画pdf用itext调整表格宽度、自定义各个列宽的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-01-31- 这篇文章主要介绍了超简洁java实现双色球若干注随机号码生成(实例代码),本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-04-02
- 这篇文章主要介绍了Java生成随机姓名、性别和年龄的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-10-01
- 这篇文章主要介绍了java正则表达式判断前端参数修改表中另一个字段的值,需要的朋友可以参考下...2021-05-07
Java使用ScriptEngine动态执行代码(附Java几种动态执行代码比较)
这篇文章主要介绍了Java使用ScriptEngine动态执行代码,并且分享Java几种动态执行代码比较,需要的朋友可以参考下...2021-04-15- 这篇文章主要介绍了Java开发实现人机猜拳游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-08-03
- 这篇文章主要介绍了Java List集合返回值去掉中括号('[ ]')的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-08-29
Java 8 Stream 的终极技巧——Collectors 功能与操作方法详解
这篇文章主要介绍了Java 8 Stream Collectors 功能与操作方法,结合实例形式详细分析了Java 8 Stream Collectors 功能、操作方法及相关注意事项,需要的朋友可以参考下...2020-05-20Java中lombok的@Builder注解的解析与简单使用详解
这篇文章主要介绍了Java中lombok的@Builder注解的解析与简单使用,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-01-06- 下面小编就为大家带来一篇java中String类型变量的赋值问题介绍。小编觉得挺不错的。现在分享给大家,给大家一个参考。...2016-03-28
- 这篇文章主要介绍了Java连接数据库oracle中文乱码解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-05-16
- 这篇文章主要介绍了Java线程池中的各个参数如何合理设置操作,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-06-19