基于javaweb的个人投资理财系统(java+springboot+layui+html+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的个人投资理财系统(java+SpringBoot+layui+html+Mysql)
一、项目运行 环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
SpringBoot + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等
登陆控制层:
@Controller
@RequestMapping(“/login”)
public class LoginController {
@Autowired
UserService userService;
@Autowired
AdminService adminService;
//public static final Map<String, HttpSession> USR_SESSION = new HashMap<>();
public static String last_login = “”;
@GetMapping(“/loginVerifyUsername/{username}”)
@ResponseBody
public Msg loginVerifyUsername(@PathVariable(“username”) String username) {
User user = userService.selectUserByTerms(username, null);
if (user != null) {
return Msg.success();
Admin admin = adminService.selectAdminByTerms(username, null);
if (admin != null) {
return Msg.success();
return Msg.fail();
@GetMapping(“/verifyLogin”)
@ResponseBody
public Msg verifyLogin(@RequestParam(“username”) String username, @RequestParam(“password”) String password,
HttpSession session) {
User loginUser = userService.selectUserByTerms(username, password);
if (loginUser != null) {
//获取当前用户
Subject subject = SecurityUtils.getSubject();
//封装用户登录数据
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
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”, “/”);
用户信息控制层:
@Controller
public class UserController {
@Autowired
UserService userService;
/**
-
跳转到账户安全界面(用户)(修改密码)
-
@param model
-
@return
*/
@RequestMapping(“/user/personal/toSecurity.html”)
public String toSecurity(Model model) {
model.addAttribute(“pageTopBarInfo”, “账户安全界面”);
model.addAttribute(“activeUrl1”, “personalActive”);
model.addAttribute(“activeUrl2”, “securityActive”);
return “/user/personal/security”;
/**
-
跳转到个人信息界面(用户)
-
@param model
-
@param session
-
@return
*/
@RequestMapping(“/user/personal/toProfile.html”)
public String toProfile(Model model, HttpSession session) {
User loginUser = (User) session.getAttribute(“loginUser”);
User user = userService.selectUserById(loginUser.getId());
model.addAttribute(“user”, user);
model.addAttribute(“pageTopBarInfo”, “个人信息界面”);
return “/user/personal/profile”;
/**
-
判断并更新密码(用户)
-
@param request
-
@return
*/
@PutMapping(“/user/updatePwd”)
@ResponseBody
public Msg updatePwd(HttpServletRequest request, HttpSession session) {
String id = request.getParameter(“id”);
User user = userService.selectUserById(Integer.valueOf(id));
String oldpwd = request.getParameter(“oldpwd”);
String newpwd = request.getParameter(“newpwd”);
User verifyExistUser = userService.selectUserByTerms(user.getUsername(), oldpwd);
if (verifyExistUser != null) {
user.setPassword(newpwd);
// 当前登录用户信息改变时session里面存储的用户信息也应该同时改变
User loginUser = (User) session.getAttribute(“loginUser”);
if (Integer.valueOf(id) == (loginUser.getId())) {
session.setAttribute(“loginUser”, user);
userService.updateUser(user);
return Msg.success();
return Msg.fail();
/**
-
更新用户信息(用户更改自己信息)
-
@param id
-
@param user
-
@param session
-
@return
*/
@PutMapping(“/user/updateUserProfile/{userId}”)
@ResponseBody
public Msg updateUserProfile(@PathVariable(“userId”) Integer id, User user, HttpSession session) {
user.setId(id);
Integer result = userService.updateUser(user);
if (result == 1) {
// 当前登录用户信息改变时session里面存储的用户信息也应该同时改变
User loginUser = (User) session.getAttribute(“loginUser”);
if (loginUser!=null){
if (id == (loginUser.getId())) {
session.setAttribute(“loginUser”, userService.selectUserById(id));
return Msg.success();
return Msg.fail();
/**
-
用户强制下线(管理员更改用户信息)
-
@param id
-
@param session
-
@return
*/
@PutMapping(“/user/updateUserStatus/{id}”)
@ResponseBody
public Msg updateUserStatus(@PathVariable(“id”) Integer id, HttpSession session) {
User user = userService.selectUserById(id);
user.setStatus(0);
Integer result = userService.updateUser(user);
if (result == 1) {
// 当前登录用户强制下线
session.removeAttribute(“loginUser”);
return Msg.success();
return Msg.fail();
/**
-
跳转到用户信息界面(管理员)
-
@param pageNum
-
@param pageSize
-
@param model
-
@param session
-
@return
*/
@GetMapping(“/admin/userinfo/toUserInfo.html”)
public String toUserInfo(@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 list = userService.selectAllUser();
// 使用PageInfo包装查询后的结果,并交给页面处理
// PageInfo封装了详细的分页信息,包括我们查询出来的数据,还可以传入连续显示的页数(5)
PageInfo pageInfo = new PageInfo(list, 5);
model.addAttribute(“userPageInfo”,pageInfo);
model.addAttribute(“userList”,list);
model.addAttribute(“activeUrl1”, “userInfoActive”);
model.addAttribute(“activeUrl2”, “userInfoActive”);
model.addAttribute(“pageTopBarInfo”, “用户信息界面”);
return “/admin/userinfo/userinfo”;
/**
-
添加用户(管理员)
-
@param user
-
@return
*/
@PostMapping(“/user/addUser”)
@ResponseBody
public Msg addUser(User user){
user.setStatus(0);
user.setReputation(“良好”);
Integer result = userService.insertUser(user);
if (result==1){
return Msg.success();
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
*/
@GetMapping(“/admin/userinfo/toReputation.html”)
public String toUserReputation(@RequestParam(value = “pageNum”, defaultValue = “1”) Integer pageNum,
@RequestParam(value = “pageSize”, defaultValue = “5”) Integer pageSize,
Model model, HttpSession session) {
PageHelper.startPage(pageNum, pageSize);
List list = userService.selectAllUser();
PageInfo pageInfo = new PageInfo(list, 5);
model.addAttribute(“userPageInfo”,pageInfo);
model.addAttribute(“userList”,list);
model.addAttribute(“activeUrl1”, “userInfoActive”);
model.addAttribute(“activeUrl2”, “reputationActive”);
model.addAttribute(“pageTopBarInfo”, “用户信誉界面”);
return “/admin/userinfo/reputation”;
银行卡管理界面:
@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 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
public Msg addBankCard(Bankcard bankcard, HttpSession session) {
//System.out.println(bankcard.getCardbank());
User loginUser = (User) session.getAttribute(“loginUser”);
bankcard.setUserid(loginUser.getId());
Integer result = bankCardService.insertBankCard(bankcard);
if (result == 1) {
return Msg.success();
return Msg.fail();
/**
-
修改银行卡时回显银行卡信息
-
@param id
-
@return
*/
@GetMapping(“/user/getBankCardById/{id}”)
@ResponseBody
public Msg getBankCardById(@PathVariable(“id”) Integer id) {
Bankcard bankcard = bankCardService.selectBankCardById(id);
return Msg.success().add(“bankcard”, bankcard);
/**
-
修改银行卡信息
-
@param id
-
@param bankcard
-
@return
*/
@PutMapping(“/user/updateBankCard/{update-id}”)
@ResponseBody
public Msg updateBankCard(@PathVariable(“update-id”) Integer id, Bankcard bankcard) {
bankcard.setId(id);
Integer result = bankCardService.updateBankCard(bankcard);
if (result == 1) {
return Msg.success();
return Msg.fail();
/**
-
删除银行卡
-
@param id
-
@return
*/
@DeleteMapping(“/user/deleteBankCard/{id}”)
@ResponseBody
public Msg deleteBankCard(@PathVariable(“id”) Integer id) {
Integer result = bankCardService.deleteBankCardById(id);
if (result == 1) {
return Msg.success();
return Msg.fail();
/**
-
跳转到银行卡管理界面(管理员)
-
@param pageNum
-
@param pageSize
-
@param model
-
@param session
-
@return
*/
@GetMapping(“/admin/userinfo/toBankCard.html”)
public String toBankCard1(@RequestParam(value = “pageNum”, defaultValue = “1”) Integer pageNum,
@RequestParam(value = “pageSize”, defaultValue = “5”) Integer pageSize,
Model model, HttpSession session) {
PageHelper.startPage(pageNum, pageSize);
List list = bankCardService.selectAllBankCard();
PageInfo pageInfo = new PageInfo(list, 5);
model.addAttribute(“bankcardPageInfo”,pageInfo);
model.addAttribute(“bankcardList”,list);
model.addAttribute(“pageTopBarInfo”, “银行卡管理界面”);
model.addAttribute(“activeUrl1”, “userInfoActive”);
model.addAttribute(“activeUrl2”, “bankcardActive”);
return “/admin/userinfo/bankcard”;