这是一个JavaWeb的课程设计,是springboot做后端,比起其他的传统项目更容易配置,导入直接运行就可以了。本系统有着前端姐界面和后端管理系统,后端管理系统又分为管理员和用户。方便供初始者学习使用和作为课程设计作业是十分合适的。
项目演示 系统前端首页 系统登录页 管理员登录页 普通用户登录页 用户注册管理员信息
用户信息 保险人信息 受益人信息 个人信息 部分代码 index.html
home
管理员信息
用户信息
保险人信息
收益人信息
数据图表
AccountController
package com.example.controller;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.example.common.Result;
import com.example.common.ResultCode;
import com.example.entity.Account;
import com.example.entity.AuthorityInfo;
import com.example.exception.CustomException;
import com.example.entity.AdminInfo;
import com.example.entity.UserInfo;
import com.example.service.AdminInfoService;
import com.example.service.UserInfoService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import cn.hutool.json.JSONUtil;
import java.util.*;
import java.util.stream.Collectors;
@RestController
public class AccountController {
@Value("${authority.info}")
private String authorityStr;
@Resource
private AdminInfoService adminInfoService;
@Resource
private UserInfoService userInfoService;
@PostMapping("/login")
public Result login(@RequestBody Account account, HttpServletRequest request) {
if (StrUtil.isBlank(account.getName()) || StrUtil.isBlank(account.getPassword()) || account.getLevel() == null) {
throw new CustomException(ResultCode.PARAM_LOST_ERROR);
}
Integer level = account.getLevel();
Account login = new Account();
if (1 == level) {
login = adminInfoService.login(account.getName(), account.getPassword());
}
if (2 == level) {
login = userInfoService.login(account.getName(), account.getPassword());
}
request.getSession().setAttribute("user", login);
return Result.success(login);
}
@PostMapping("/register")
public Result register(@RequestBody Account account) {
Integer level = account.getLevel();
Account login = new Account();
if (1 == level) {
AdminInfo info = new AdminInfo();
BeanUtils.copyProperties(account, info);
login = adminInfoService.add(info);
}
if (2 == level) {
UserInfo info = new UserInfo();
BeanUtils.copyProperties(account, info);
login = userInfoService.add(info);
}
return Result.success(login);
}
@GetMapping("/logout")
public Result logout(HttpServletRequest request) {
request.getSession().setAttribute("user", null);
return Result.success();
}
@GetMapping("/auth")
public Result getAuth(HttpServletRequest request) {
Object user = request.getSession().getAttribute("user");
if(user == null) {
return Result.error("401", "未登录");
}
return Result.success(user);
}
@GetMapping("/getAccountInfo")
public Result
UserInfo
package com.example.entity;
import javax.persistence.*;
@Table(name = "user_info")
public class UserInfo extends Account {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "name")
private String name;
@Column(name = "password")
private String password;
@Column(name = "guoji")
private String guoji;
@Column(name = "sex")
private String sex;
@Column(name = "age")
private Integer age;
@Column(name = "birthday")
private String birthday;
@Column(name = "phone")
private String phone;
@Column(name = "address")
private String address;
@Column(name = "email")
private String email;
@Column(name = "cardId")
private String cardId;
@Column(name = "level")
private Integer level;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getGuoji() {
return guoji;
}
public void setGuoji(String guoji) {
this.guoji = guoji;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getCardId() {
return cardId;
}
public void setCardId(String cardId) {
this.cardId = cardId;
}
public Integer getLevel() {
return level;
}
public void setLevel(Integer level) {
this.level = level;
}
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return this.id;
}
}
AdminInfoService
package com.example.service;
import com.example.dao.AdminInfoDao;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.example.entity.AdminInfo;
import com.example.exception.CustomException;
import com.example.common.ResultCode;
import com.example.vo.AdminInfoVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.crypto.SecureUtil;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
@Service
public class AdminInfoService {
@Resource
private AdminInfoDao adminInfoDao;
public AdminInfo add(AdminInfo adminInfo) {
// 唯一校验
int count = adminInfoDao.checkRepeat("name", adminInfo.getName(), null);
if (count > 0) {
throw new CustomException("1001", "用户名"" + adminInfo.getName() + ""已存在");
}
if (StringUtils.isEmpty(adminInfo.getPassword())) {
// 默认密码123456
adminInfo.setPassword(SecureUtil.md5("123456"));
} else {
adminInfo.setPassword(SecureUtil.md5(adminInfo.getPassword()));
}
adminInfoDao.insertSelective(adminInfo);
return adminInfo;
}
public void delete(Long id) {
adminInfoDao.deleteByPrimaryKey(id);
}
public void update(AdminInfo adminInfo) {
adminInfoDao.updateByPrimaryKeySelective(adminInfo);
}
public AdminInfo findById(Long id) {
return adminInfoDao.selectByPrimaryKey(id);
}
public List findAll() {
return adminInfoDao.findByName("all");
}
public PageInfo findPage(String name, Integer pageNum, Integer pageSize, HttpServletRequest request) {
PageHelper.startPage(pageNum, pageSize);
List all = adminInfoDao.findByName(name);
return PageInfo.of(all);
}
public AdminInfoVo findByUserName(String name) {
return adminInfoDao.findByUsername(name);
}
public AdminInfo login(String username, String password) {
AdminInfo adminInfo = adminInfoDao.findByUsername(username);
if (adminInfo == null) {
throw new CustomException(ResultCode.USER_ACCOUNT_ERROR);
}
if (!SecureUtil.md5(password).equalsIgnoreCase(adminInfo.getPassword())) {
throw new CustomException(ResultCode.USER_ACCOUNT_ERROR);
}
return adminInfo;
}
}
项目是在IDEA上做的,IDEA是一个写java代码特别好的软件,安装也不会麻烦,我也有破解版教程可以提供,如果有需要项目的源码的话,可以加我扣扣2378796706交流一下。欢迎大家一起交流学习!



