基于javaweb+mysql的springboot理财管理系统设计和实现(java+springboot+ssm+thymeleaf+html)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot理财管理系统设计和实现(java+springboot+ssm+thymeleaf+html)
spring boot,spring,spring mvc,mybatis,shiro框架分页处理使用了pagehelper进行操作,前台使用了模板语言thymeleaf,界面较为炫酷,适合年轻朋友。开发工具采用的是IDEA。该系统主要解决了理财中的一些问题,包含功能:权限管理,用户信息管理,理财产品管理等内容。
主要分为管理员和普通用户两种用户;
1.管理员模块主要包括:
用户信息管理:用户信息、银行卡、个人征信;
理财产品管理:零钱理财、工资理财、期限理财、基金理财、精选银行;
权限管理:用户权限、管理员权限
网贷管理:网贷审核、网贷信息;
2.普通用户模块主要包括
个人理财:零钱理财、工资理财、期限理财、基金理财、银行推荐;
金融工具:资金记录、安全网贷;
个人中心:我的理财、我的借贷、银行卡管理、账户安全;
// 跳转到请求的资源,并传入自己定义的myRequest对象
chain.doFilter(myRequest, response);
}
public void init(FilterConfig fConfig) throws ServletException {
// 获取配置的编码格式
code = fConfig.getInitParameter("code");
// 获取xml文件<init-param>标签中code的value//如果没有配置,就使用UTF-8默认编码
this.code = code == null || "".equals(code.trim()) ? "utf-8" : code;
}
// 重新定义一个自己的request对象,继承HttpServletRequestWrapper 这个HttpServletRequest的适配器
class MyHttpServletRequest extends HttpServletRequestWrapper {
public MyHttpServletRequest(HttpServletRequest request) {
super(request);
}
// 重写getParameter方法
@Override
public String getParameter(String name) {
String value = super.getParameter(name);
if (value == null)
return null;
// 判断只要不是“get”方式提交就直接返回,equalsIgnoreCase方法是不考虑大小写的匹配
if (!"get".equalsIgnoreCase(super.getMethod()))
return value;
// 如果请求方式为"get",那么就进行加码,解码码表为父类的码表
try {
value = new String(value.getBytes("ISO-8859-1"), super.getCharacterEncoding());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return value;
}
}
}
@Controller
public class RecoderController {
@Autowired
FlowOfFundsService flowOfFundsService;
/**
* 跳转到资金记录界面
* @param model
* @return
*/
@RequestMapping("/user/tools/toRecord.html")
public String toRecoder(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
Model model, HttpSession session) {
// 引入PageHelper插件,在查询之前调用startPage方法,传入页码以及每页大小
PageHelper.startPage(pageNum, pageSize);
User user = (User) session.getAttribute("loginUser");
List<FlowOfFunds> list = flowOfFundsService.selectFlowOfFundsByUserId(user.getId());
// 使用PageInfo包装查询后的结果,并交给页面处理
// PageInfo封装了详细的分页信息,包括我们查询出来的数据,还可以传入连续显示的页数(5)
PageInfo<FlowOfFunds> pageInfo = new PageInfo<FlowOfFunds>(list, 5);
model.addAttribute("flowOfFundsList",list);
model.addAttribute("flowOfFundsPageInfo",pageInfo);
model.addAttribute("pageTopBarInfo", "资金记录界面");
model.addAttribute("activeUrl1", "toolsActive");
model.addAttribute("activeUrl2", "recordActive");
return "/user/tools/record";
}
}
}
}
@Controller
public class BankCardController {
@Autowired
BankCardService bankCardService;
/**
* 跳转到银行卡管理界面(用户)
*
* @param model
* @param session
* @return
*/
@GetMapping("/user/personal/toBankCard.html")
public String toBankCard(Model model, HttpSession session) {
User loginUser = (User) session.getAttribute("loginUser");
List<Bankcard> list = bankCardService.selectBankCardByUserId(loginUser.getId());
model.addAttribute("bankCardList", list);
model.addAttribute("pageTopBarInfo", "银行卡管理界面");
model.addAttribute("activeUrl1", "personalActive");
model.addAttribute("activeUrl2", "bankCardActive");
return "/user/personal/bankcard";
}
/**
* 新增银行卡
*
* @param bankcard
* @param session
* @return
*/
@PostMapping("/user/addBankCard")
@ResponseBody
/**
* 跳转到基金理财界面
* @param model
* @return
*/
@RequestMapping("/user/finance/toFundProduct.html")
public String toFundProduct(Model model){
List<FundProduct> list = fundProductService.selectAllFundProduct();
model.addAttribute("fundProductList",list);
model.addAttribute("pageTopBarInfo","基金理财界面");
model.addAttribute("activeUrl1","financeActive");
model.addAttribute("activeUrl2","fundProductActive");
return "/user/finance/fundproduct";
}
/**
* 购买基金理财产品
* @param fundProductId
* @param userId
* @return
*/
@PostMapping("/user/buyFundProduct")
@ResponseBody
public Msg buyFundProduct(@RequestParam("fundProductId")Integer fundProductId,
@RequestParam("userId") Integer userId ){
UserFundProduct ufp = new UserFundProduct();
ufp.setUserid(userId);
ufp.setFundid(fundProductId);
ufp.setStarttime(new Date());
FundProduct fp = fundProductService.selectFundProductById(fundProductId);
ufp.setAveryield(fp.getMonthlygrowth());
ufp.setProfit(fp.getLeastmoney().multiply(fp.getMonthlygrowth()));
ufp.setStatus(1);
Integer result = userFundProductService.insertUserFundProduct(ufp);
if (result==1){
FlowOfFunds fof = new FlowOfFunds();
fof.setUserid(userId);
fof.setFlowmoney(fp.getLeastmoney());
fof.setType(1);
fof.setSource(fp.getFunddesc());
fof.setCreatetime(new Date());
fof.setFunddesc("无");
flowOfFundsService.insertFlowOfFunds(fof);
return Msg.success();
}else {
return Msg.fail();
}
}
/**
* 跳转到基金理财管理界面(管理员)
*/
@DeleteMapping("/admin/deletePayMoneyById/{id}")
@ResponseBody
public Msg deletePayMoneyById(@PathVariable("id") Integer id){
Integer result = payMoneyService.deletePayMoneyById(id);
if (result==1){
return Msg.success();
}
return Msg.fail();
}
}
@Controller
public class MyFinanceController {
@Autowired
UserChangeMoneyService userChangeMoneyService;
@Autowired
UserPayMoneyService userPayMoneyService;
@Autowired
UserFundProductService userFundProductService;
@Autowired
UserTermFinancialService userTermFinancialService;
@GetMapping("/user/personal/toMyFinance.html")
public String toMyFinance(Model model, HttpSession session) {
// PageInfo封装了详细的分页信息,包括我们查询出来的数据,还可以传入连续显示的页数(5)
PageInfo<User> pageInfo = new PageInfo<User>(list, 5);
model.addAttribute("userPageInfo",pageInfo);
model.addAttribute("userList",list);
model.addAttribute("pageTopBarInfo","系统首页");
model.addAttribute("activeUrl","indexActive");
return "admin/main";
}
/**
* 用户首页
* @param model
* @return
*/
@GetMapping("/user/index.html")
public String toUserIndex(Model model){
List<News> list = newsService.selectAllNews();
model.addAttribute("newsList",list);
model.addAttribute("pageTopBarInfo","系统首页");
model.addAttribute("activeUrl","indexActive");
return "user/main";
}
/**
* 注销(只有正常退出的用户可以注销)
* @param session
* @return
*/
@GetMapping("/logout")
public String logout(@RequestParam("logout")String logout, HttpSession session) {
if ("userLogout".equals(logout)){
User loginUser = (User) session.getAttribute("loginUser");
User user = userService.selectUserById(loginUser.getId());
user.setStatus(0);
userService.updateUser(user);
session.removeAttribute("loginUser");
System.out.println("logout==>"+user.getUsername()+"已退出系统");
return "login";
}
if ("adminLogout".equals(logout)){
Admin loginAdmin = (Admin) session.getAttribute("loginAdmin");
Admin admin =adminService.selectAdminById(loginAdmin.getId());
admin.setStatus(0);
adminService.updateAdmin(admin);
session.removeAttribute("loginAdmin");
System.out.println("logout==>"+admin.getUsername()+"已退出系统");
return "login";
}
return "login";
return Msg.success();
}
}
@Controller
public class BankCardController {
@Autowired
BankCardService bankCardService;
/**
* 跳转到银行卡管理界面(用户)
*
* @param model
* @param session
* @return
*/
@GetMapping("/user/personal/toBankCard.html")
public String toBankCard(Model model, HttpSession session) {
User loginUser = (User) session.getAttribute("loginUser");
List<Bankcard> list = bankCardService.selectBankCardByUserId(loginUser.getId());
model.addAttribute("bankCardList", list);
model.addAttribute("pageTopBarInfo", "银行卡管理界面");
model.addAttribute("activeUrl1", "personalActive");
@Controller
public class PermissionsController {
@Autowired
UserPermissionsService userPermissionsService;
@Autowired
PermissionsService permissionsService;
@Autowired
AdminPermissionsService adminPermissionsService;
/**
* 跳转到用户权限管理界面(管理员)
* @param model
* @param session
* @return
*/
@GetMapping("/admin/permission/toUserPermissions.html")
public String toUserPermission(Model model, HttpSession session) {
List<UserPermissions> list = userPermissionsService.selectUserPermissionsByUserId(1);
ArrayList<String> list2 = new ArrayList<>();
for (UserPermissions userPermissions : list) {
list2.add(userPermissions.getPermissions().getPermission());
}
model.addAttribute("permissionsList", list2);
//session.setAttribute("permissionsList",list);
model.addAttribute("activeUrl1", "permissionActive");
model.addAttribute("activeUrl2", "userPermissionsActive");
model.addAttribute("pageTopBarInfo", "用户权限管理界面");
return "/admin/permission/userpermissions";
}
/**
* 更新用户权限
* @param userPermissions
* @return
*/
@PutMapping("/admin/updateUserPermissions")
@ResponseBody
}
// 重新定义一个自己的request对象,继承HttpServletRequestWrapper 这个HttpServletRequest的适配器
class MyHttpServletRequest extends HttpServletRequestWrapper {
public MyHttpServletRequest(HttpServletRequest request) {
super(request);
}
// 重写getParameter方法
@Override
public String getParameter(String name) {
String value = super.getParameter(name);
if (value == null)
return null;
// 判断只要不是“get”方式提交就直接返回,equalsIgnoreCase方法是不考虑大小写的匹配
if (!"get".equalsIgnoreCase(super.getMethod()))
return value;
// 如果请求方式为"get",那么就进行加码,解码码表为父类的码表
try {
value = new String(value.getBytes("ISO-8859-1"), super.getCharacterEncoding());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return value;
}
}
}
@Controller
public class InfoController {
@Autowired
return Msg.success();
}
return Msg.fail();
}
/**
* 更新时回显信息
* @param id
* @return
*/
@GetMapping("/admin/getPayMoneyInfoById/{id}")
@ResponseBody
public Msg getPayMoneyInfoById(@PathVariable("id") Integer id){
PayMoney payMoney = payMoneyService.selectPayMoneyById(id);
return Msg.success().add("payMoney",payMoney);
}
/**
* 更新
* @param id
* @param payMoney
* @return
*/
@PutMapping("/admin/updatePayMoney/{id}")
@ResponseBody
public Msg updatePayMoney(@PathVariable("id") Integer id,PayMoney payMoney){
payMoney.setId(id);
Integer result = payMoneyService.updatePayMoney(payMoney);
if (result==1){
return Msg.success();
}
return Msg.fail();
}
/**
* 删除
* @param id
* @return
*/
@DeleteMapping("/admin/deletePayMoneyById/{id}")
@ResponseBody
* @param session
* @return
*/
@GetMapping("/admin/loan/toLoaninfo.html")
public String toLoaninfo(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
Model model, HttpSession session) {
// 引入PageHelper插件,在查询之前调用startPage方法,传入页码以及每页大小
PageHelper.startPage(pageNum, pageSize);
List<Loan> list = loanService.selectAllExamedLoan();
// 使用PageInfo包装查询后的结果,并交给页面处理
// PageInfo封装了详细的分页信息,包括我们查询出来的数据,还可以传入连续显示的页数(5)
PageInfo<Loan> pageInfo = new PageInfo<Loan>(list, 5);
model.addAttribute("loanPageInfo", pageInfo);
model.addAttribute("loanList", list);
model.addAttribute("activeUrl1", "loanActive");
model.addAttribute("activeUrl2", "loaninfoActive");
model.addAttribute("pageTopBarInfo", "网贷信息界面");
return "admin/loan/loaninfo";
}
@PutMapping("/loan/remindPay/{id}")
@ResponseBody
public Msg remindPay(@PathVariable("id") Integer id, HttpSession session) {
Admin admin = (Admin) session.getAttribute("loginAdmin");
Loan loan = loanService.selectLoanById(id);
Info info = new Info();
info.setSendid(admin.getId());
info.setReceiveid(loan.getUser().getId());
info.setCreatetime(new Date());
info.setTitle("还款通知");
info.setInfodesc("用户" + loan.getUser().getUsername() + "申请的" + loan.getAmount() + "元网贷该还款了!该提醒发送人为:" + admin.getUsername());
info.setStatus(0);
Integer result = infoService.insertInfo(info);
if (result == 1) {
return Msg.success();
}
return Msg.fail();
}
}
public MyHttpServletRequest(HttpServletRequest request) {
super(request);
}
// 重写getParameter方法
@Override
public String getParameter(String name) {
String value = super.getParameter(name);
if (value == null)
return null;
// 判断只要不是“get”方式提交就直接返回,equalsIgnoreCase方法是不考虑大小写的匹配
if (!"get".equalsIgnoreCase(super.getMethod()))
return value;
// 如果请求方式为"get",那么就进行加码,解码码表为父类的码表
try {
value = new String(value.getBytes("ISO-8859-1"), super.getCharacterEncoding());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return value;
}
}
}
return Msg.success();
}
return Msg.fail();
}
}
@Controller
public class FundProductController {
@Autowired
FundProductService fundProductService;
@Autowired
UserFundProductService userFundProductService;
@Autowired
FlowOfFundsService flowOfFundsService;
/**
* 跳转到基金理财界面
* @param model
* @return
*/
try {
subject.login(token);
return Msg.success().add("url", "/user/index.html");
} catch (UnknownAccountException | IncorrectCredentialsException e) {
return Msg.fail();
}
}
Admin admin = adminService.selectAdminByTerms(username, password);
if (admin != null) {
//获取当前用户
Subject subject = SecurityUtils.getSubject();
//封装用户登录数据
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
try {
subject.login(token);
return Msg.success().add("url", "/admin/index.html");
} catch (UnknownAccountException | IncorrectCredentialsException e) {
//model.addAttribute("msg","密码错误");
return Msg.fail();
}
}
return Msg.fail();
}
@PostMapping("/register")
@ResponseBody
public Msg register(@RequestParam("username") String username, @RequestParam("password") String password) {
User user = new User();
user.setUsername(username);
user.setPassword(password);
user.setStatus(0);
user.setReputation("良好");
userService.insertUser(user);
return Msg.success().add("url", "/");
}
}
* @param payMoneyId
* @param userId
* @return
*/
@PostMapping("/user/buyPayMoney")
@ResponseBody
public Msg buyPayMoney(@RequestParam("payMoneyId")Integer payMoneyId,
@RequestParam("userId") Integer userId ){
PayMoney pm = payMoneyService.selectPayMoneyById(payMoneyId);
UserPayMoney upm = new UserPayMoney();
upm.setUserid(userId);
upm.setPayid(payMoneyId);
upm.setStarttime(new Date());
upm.setAveryield(new BigDecimal("0.03123"));
upm.setProfit(new BigDecimal("0.03123").multiply(pm.getMonthmoney()));
upm.setStatus(1);
Integer result = userPayMoneyService.insertUserPayMoney(upm);
if (result==1){
FlowOfFunds fof = new FlowOfFunds();
fof.setUserid(userId);
fof.setFlowmoney(pm.getMonthmoney());
fof.setType(1);
fof.setSource("工资理财");
fof.setCreatetime(new Date());
if (pm.getType()==1){
fof.setFunddesc("国债");
}else if(pm.getType()==2){
fof.setFunddesc("期货");
}
flowOfFundsService.insertFlowOfFunds(fof);
return Msg.success();
}else {
return Msg.fail();
}
}
/**
* 跳转到工资理财管理界面(管理员)
* @param pageNum
* @param pageSize
* @param model
* @param session
* @return
*/
@GetMapping("/admin/finance/toPayMoney.html")
public String toPayMoneyInfo(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
Model model, HttpSession session) {
}
return Msg.fail();
}
/**
* 更新用户信息时回显用户信息(管理员)
* @param id
* @return
*/
@GetMapping("/user/getUserById/{id}")
@ResponseBody
public Msg getUserInfoById(@PathVariable("id")Integer id){
User user = userService.selectUserById(id);
return Msg.success().add("user",user);
}
/**
* 删除用户(管理员)
* @param id
* @param session
* @return
*/
@DeleteMapping("/user/deleteUserById/{id}")
@ResponseBody
public Msg deleteUserById(@PathVariable("id")Integer id,HttpSession session){
Integer result = userService.deleteUserById(id);
if (result==1){
// 删除用户时应先判断这个用户是否在线
User loginUser = (User) session.getAttribute("loginUser");
if (loginUser!=null){
if (id == (loginUser.getId())) {
session.removeAttribute("loginUser");
}
}
return Msg.success();
}
return Msg.fail();
}
/**
* 跳转到用户信誉管理界面(管理员)
* @param pageNum
* @param pageSize
* @param model
* @param session
* @return
model.addAttribute("bankList",list);
model.addAttribute("pageTopBarInfo","银行推荐界面");
model.addAttribute("activeUrl1","financeActive");
model.addAttribute("activeUrl2","bankActive");
return "user/finance/bank";
}
/**
* 跳转到推荐银行管理界面(管理员)
* @param pageNum
* @param pageSize
* @param model
* @param session
* @return
*/
@GetMapping("/admin/finance/toBank.html")
public String toBank(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
Model model, HttpSession session) {
PageHelper.startPage(pageNum, pageSize);
List<Bank> list = bankService.selectAllBank();
PageInfo<Bank> pageInfo = new PageInfo<Bank>(list, 5);
model.addAttribute("finacnePageInfo",pageInfo);
model.addAttribute("financeList",list);
model.addAttribute("activeUrl1", "financeActive");
model.addAttribute("activeUrl2", "bankctive");
model.addAttribute("pageTopBarInfo", "推荐银行管理界面");
return "/admin/finance/bank";
}
/**
* 新增推荐银行
*
* @return
*/
@PostMapping("/admin/addBank")
@ResponseBody
public Msg addBank(Bank bank){
Integer result = bankService.insertBank(bank);
if (result==1){
return Msg.success();
}
return Msg.fail();
}
/**
List<FlowOfFunds> list = flowOfFundsService.selectFlowOfFundsByUserId(user.getId());
// 使用PageInfo包装查询后的结果,并交给页面处理
// PageInfo封装了详细的分页信息,包括我们查询出来的数据,还可以传入连续显示的页数(5)
PageInfo<FlowOfFunds> pageInfo = new PageInfo<FlowOfFunds>(list, 5);
model.addAttribute("flowOfFundsList",list);
model.addAttribute("flowOfFundsPageInfo",pageInfo);
model.addAttribute("pageTopBarInfo", "资金记录界面");
model.addAttribute("activeUrl1", "toolsActive");
model.addAttribute("activeUrl2", "recordActive");
return "/user/tools/record";
}
}
/**
* 登陆拦截器:未登录用户不能访问系统界面
*/
public class LoginHandlerInterceptor implements HandlerInterceptor {
//目标方法执行之前
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
Object user = request.getSession().getAttribute("loginUser");
Object admin = request.getSession().getAttribute("loginAdmin");
if(user == null&&admin==null){
//未登陆,返回登陆页面
request.setAttribute("msg","没有权限请先登陆");
System.out.println("LoginHandlerInterceptor.preHandle" + "----------------未登入------拦截请求--------------->");
response.sendRedirect("/");
return false;
}else{
//已登陆,放行请求
return true;
}
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}