基于javaweb的校园班级同学通讯录管理系统(java+ssm+html+jsp+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的校园班级同学通讯录管理系统(java+SSM+HTML+JSP+mysql)
项目介绍
管理员角色包含以下功能: 管理员登录,修改管理员资料,用户管理,公告管理,系别信息管理,班级管理,学生通讯录管理等功能。
用户角色包含以下功能: 用户登录,修改个人资料,查看公告,查看系别信息,班级查看,学生通讯信息查看等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:HTML+CSS+JavaScript+jsp
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application.yml配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/ 登录
用户管理控制层:
@RequestMapping(“/user”)
@RestController //标识为返回类型为Json的控制器
public class UserController {
//自动注入服务类
@Autowired
private IUserService userService;
@Autowired
private TStudentService studentService;
//标识请求地址
@RequestMapping(“/login”)
public ResultObject<List> getUsers(User user,HttpServletRequest request) {
//查询用户列表
List list= userService.getUser(user);
ResultObject<List> rs=new ResultObject<List>();
if(list.isEmpty()) {
//状态码
rs.setCode(Constant.FAILURE_RETUEN_CODE);
//提示
rs.setMsg(“登录失败”);
}else {
//状态码
rs.setCode(Constant.SUCCESS_RETUEN_CODE);
request.getSession().setAttribute(“user”, list.get(0));
//提示
rs.setMsg(“登录成功”);
//数据
rs.setData(list);
return rs;
@RequestMapping(“/loginOut”)
public ResultObject loginOut(HttpServletRequest request) {
//查询用户列表
ResultObject rs=new ResultObject();
request.getSession().removeAttribute(“user”);
//数据
rs.setCode(Constant.SUCCESS_RETUEN_CODE);
rs.setMsg(“退出成功”);
return rs;
//标识请求地址
@RequestMapping(“/studentLogin”)
public ResultObject<List> studentLogin(User user,HttpServletRequest request) {
//查询用户列表
TStudent student=new TStudent();
student.setStudentNo(Integer.parseInt(user.getUserName()));
student.setStuPass(user.getPassword());
List list= studentService.selectloginStudent(student);
ResultObject<List> rs=new ResultObject<List>();
if(list.isEmpty()) {
//状态码
rs.setCode(Constant.FAILURE_RETUEN_CODE);
//提示
rs.setMsg(“登录失败”);
}else {
//状态码
rs.setCode(Constant.SUCCESS_RETUEN_CODE);
request.getSession().setAttribute(“student”, list.get(0));
//提示
rs.setMsg(“登录成功”);
//数据
rs.setData(list);
return rs;
@RequestMapping(“/studentloginOut”)
public ResultObject studentloginOut(HttpServletRequest request) {
//查询用户列表
ResultObject rs=new ResultObject();
request.getSession().removeAttribute(“student”);
//数据
rs.setCode(Constant.SUCCESS_RETUEN_CODE);
rs.setMsg(“退出成功”);
return rs;
学生管理控制层:
@RequestMapping(“/student”)
@RestController //标识为返回类型为Json的控制
public class StudentController {
@Autowired
private TStudentService studentService;
//标识请求地址
@RequestMapping(“/getAllStudent”)
public ResultObject<List> getUsers(TStudent student,@RequestParam(“limit”) int limit,@RequestParam(“page”) int page) {
PageInfo pageInfo=studentService.getAll(student, page, limit);
ResultObject<List> rs=new ResultObject<List>();
rs.setCode(Constant.SUCCESS_RETUEN_CODE);
rs.setMsg(“查询成功”);
rs.setData(pageInfo.getList());
rs.setCount(pageInfo.getTotal());
return rs;
//标识请求地址
@RequestMapping(“/addStudent”)
public ResultObject addStudent(TStudent student) {
Integer studentNo=student.getStudentNo();
student.setStuPass(studentNo.toString());
TStudent result=studentService.selectByNo(studentNo);
//统一返回
ResultObject rs=new ResultObject();
if(null==result) {
studentService.addStudent(student);
rs.setCode(Constant.SUCCESS_RETUEN_CODE);
rs.setMsg(“增加学生信息成功”);
}else {
rs.setCode(Constant.HASE_RETUEN_CODE);
rs.setMsg(“学号已存在”);
return rs;
//标识请求地址
@RequestMapping(“/updateStudent”)
public ResultObject updateStudent(TStudent student) {
Integer total=studentService.updateStudent(student);
//统一返回
ResultObject rs=new ResultObject();
if(nulltotal||0total) {
rs.setCode(Constant.FAILURE_RETUEN_CODE);
rs.setMsg(“修改学生信息失败”);
}else {
rs.setCode(Constant.SUCCESS_RETUEN_CODE);
rs.setMsg(“修改学生信息成功”);
return rs;
//标识请求地址
@RequestMapping(“/deleteStudent”)
public ResultObject deleteStudent(@RequestParam(“studentNo”) int studentNo) {
Integer total=studentService.deleteStudent(studentNo);
//统一返回
ResultObject rs=new ResultObject();
if(nulltotal||0total) {
rs.setCode(Constant.FAILURE_RETUEN_CODE);
rs.setMsg(“修改学生信息失败”);
}else {
rs.setCode(Constant.SUCCESS_RETUEN_CODE);
rs.setMsg(“修改学生信息成功”);
return rs;
/**
-
获取学生下拉框
-
@return
*/
@RequestMapping(“/studentSelect”)
public ResultObject<List> studentSelect() {
ResultObject<List> rs=new ResultObject<List>();
List list=studentService.selectAllStudent();
rs.setCode(Constant.SUCCESS_RETUEN_CODE);
rs.setMsg(“查询成功”);
rs.setData(list);
int total=list.size();
Long a=Long.parseLong(String.valueOf(total));
rs.setCount(a);
return rs;
登录管理控制层:
@Controller
@RequestMapping(value=“/login”)
public class LoginController {
@Autowired
AuthService authService;
@Autowired
AdminService adminServiceImpl;
@Autowired
TeacherService teacherServiceImpl;
@Autowired
StudentService studentServiceImpl;
@RequestMapping(value=“/loginPage”)
public ModelAndView toLoginPage() {
return new ModelAndView(“login”);
@ResponseBody
@RequestMapping(value=“/doLogin”)
public String doLogin(@RequestParam(defaultValue=“”) String username,
@RequestParam(defaultValue=“”) String password,
@RequestParam(defaultValue=“0”) int userType,
@RequestParam(defaultValue=“”) String verifyCode, HttpSession session) {
//比较验证码
String sessionVerifyCode = (String) session.getAttribute(StrUtil.VERIFY_CODE);
if (sessionVerifyCode == null || !sessionVerifyCode.equals(verifyCode.toUpperCase()) ) {
return StrUtil.CODE_ERROR;
Login loginUser = null;
if (userType == 1) {
loginUser = (Login) adminServiceImpl;
} else if(userType == 2) {
loginUser = (Login) teacherServiceImpl;
} else if(userType == 3) {
loginUser = (Login) studentServiceImpl;
User user = loginUser.loginValidate(username, password.toUpperCase());//获得验证后user对象
if (user != null) {
//List menuList = authService.getMenuList(user.getUserType());
List urlList = authService.getUrlList(user.getUserType());
user.setUrlList(urlList);
//user.setMenuList(menuList);
session.setAttribute(StrUtil.USER, user);
return JSON.toJSONString(user);
return StrUtil.RESULT_FALSE;
@RequestMapping(value=“/out”)
public ModelAndView loginOut(HttpSession session) {
session.invalidate();//销毁sessions
//请求重定向到主页(login页)
return new ModelAndView(“redirect:/”);
@RequestMapping(value=“/getVerifyCode”)
public void getVerifyCode(HttpServletResponse response, HttpSession session) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
session.setAttribute(“verifyCode”, drawCodeImg(output));
try {
ServletOutputStream out = response.getOutputStream();
output.writeTo(out);
} catch (IOException e) {
e.printStackTrace();
/**
-
绘出验证码
-
@param output
-
@return
*/
private String drawCodeImg(ByteArrayOutputStream output) {
String code = “”;
for (int i = 0; i < 4; i++) {
code += randomChar();
int width = 70;
int height = 36;
BufferedImage bImage = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
Font font = new Font(“Times New Roman”, Font.PLAIN, 20);
Graphics2D graphics = bImage.createGraphics();
graphics.setFont(font);
graphics.setColor(new Color(66,2,82));
graphics.setBackground(new Color(226,226,240));
graphics.clearRect(0, 0, width, height);
FontRenderContext context = graphics.getFontRenderContext();
Rectangle2D bounds = font.getStringBounds(code, context);
double x = (width - bounds.getWidth()) / 2;
double y = (height - bounds.getHeight()) / 2;
double ascent = bounds.getY();
double baseY = y - ascent;
graphics.drawString(code, (int) x, (int) baseY);
graphics.dispose();
try {
ImageIO.write(bImage, “jpg”, output);
} catch (IOException e) {
e.printStackTrace();
return code;
/**
-
返回一个随机字符
-
@return
*/
private char randomChar() {
Random r = new Random();
String str = “ABCDEFGHJKLMNPRSTUVWXYZ0123456789”;
return str.charAt(r.nextInt(str.length()));