Java項目之java+springboot+ssm實現理財管理系統設計
理財系統:
設計使用瞭當前較為流行的spring boot
,spring,spring mvc
,mybatis
,shiro
框架分頁處理使用瞭pagehelper進行操作,
前臺使用瞭模板語言thymeleaf
,界面較為炫酷,適合年輕朋友。開發工具采用的是IDEA。
該系統主要解決瞭理財中的一些問題
包含功能:權限管理,用戶信息管理,理財產品管理等內容。
登陸控制層:
@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<User> list = userService.selectAllUser(); // 使用PageInfo包裝查詢後的結果,並交給頁面處理 // PageInfo封裝瞭詳細的分頁信息,包括我們查詢出來的數據,還可以傳入連續顯示的頁數(5) PageInfo<User> pageInfo = new PageInfo<User>(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<User> list = userService.selectAllUser(); PageInfo<User> pageInfo = new PageInfo<User>(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<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 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<Bankcard> list = bankCardService.selectAllBankCard(); PageInfo<Bankcard> pageInfo = new PageInfo<Bankcard>(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"; } }
到此這篇關於Java項目java+springboot+ssm實現理財管理系統設計的文章就介紹到這瞭,更多相關java+springboot+ssm實現理財管理系統設計內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!