java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统

基于SSM的健身房管理系统

The project was made in 2020-05-05~2020-05-10

谨以此片博文记录下我的第一个Java小Demo

项目展示

java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统_第1张图片

用户登录页

java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统_第2张图片

用户注册页

用户主页

用户购买健身卡(商城)页

java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统_第3张图片

管理员登录页

java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统_第4张图片

管理员主页

管理员添加用户页

java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统_第5张图片

管理员编辑用户页

细节1:常驻工具栏(内含搜索栏)

java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统_第6张图片

细节2:登录账号密码实时反馈(AJAX)

java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统_第7张图片

**细节3:翻页功能&可选每页显示条数 **

java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统_第8张图片

细节4:人性化的交互设计

项目环境

JDK: 1.8

IDE: IDEA 201903

DataBase: MySQL 8.0

Mybatis: 3.5.2

POM: Maven

Tomcat 9

Bootstrap 3

JQuery 2

lombok 插件

分页插件: PageHelper 5.1.11

涉及技术 MySQL数据库,Spring,JavaWeb及MyBatis,简单的前端知识

项目详情

设计数据库

大二没有好好学系统设计与分析,画的图一塌糊涂。

java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统_第9张图片

包含两个实体类,用户&管理员

生成该数据库的sql文件 在该链接跳转GitHub /sql 目录下

java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统_第10张图片

生成表如图示

设计要实现的功能

应该叫做用例图吧,但我的好多符号都是错的,再次后悔没有好好学习!

java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统_第11张图片

制作前端页面Demo

设计该图的网址

其实这一步放在后面也合适,我为了让自己吃大饼,就先设计了一下。

环境配置

java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统_第12张图片

项目文件结构如图所示

基本步骤

新建Maven项目,添加web支持

导入pom依赖

junit

junit

4.12

mysql

mysql-connector-java

5.1.47

com.mchange

c3p0

0.9.5.2

javax.servlet

servlet-api

2.5

javax.servlet.jsp

jsp-api

2.2

javax.servlet

jstl

1.2

org.mybatis

mybatis

3.5.2

org.mybatis

mybatis-spring

2.0.2

org.springframework

spring-webmvc

5.1.9.RELEASE

org.springframework

spring-jdbc

5.1.9.RELEASE

Maven资源过滤

src/main/java

**/*.properties

**/*.xml

false

src/main/resources

**/*.properties

**/*.xml

false

建立基本结构框架 (如上所示[点此跳转](# 环境配置)

建立基本配置

mybatis-config.xml

/p>

PUBLIC "-//mybatis.org//DTD Config 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-config.dtd">

applicationContext.xml

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd">

Mybatis层编写

数据库配置文件 database.properties

jdbc.driver=com.mysql.jdbc.Driver

jdbc.url=jdbc:mysql://localhost:3306/ssmbuild?useSSL=true&useUnicode=true&characterEncoding=utf8

jdbc.username=root

jdbc.password=123456IDEA关联数据库

IDEA关联数据库

编写MyBatis的核心配置文件

/p>

PUBLIC "-//mybatis.org//DTD Config 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-config.dtd">

POJO Mapper Services的编写

POJO

User

@Data //使用lombok插件即可省写get set

@AllArgsConstructor

@NoArgsConstructor

public class User {

private int id;

private String username;

private String password;

private String name;

private String sex;

private String telephone;

private int age;

private String begintime;

private String endtime;

private int remainday;

private int addday;

public static void main(String[] args) {

User u = new User();

u.getTelephone();

}

}

Admin

@Data

@NoArgsConstructor

@AllArgsConstructor

public class Admin {

private int id;

private String username;

private String password;

private String name;

private String telephone;

}

Mapper

编写DAO层的Mapper接口

1 userMapper

public interface UserMapper {

//通过id查询

User queryUserById(int id);

// 查询到期时间

Date queryDateById(int id);

//修改账号密码

int updateNP(User user);

//login

User userLogin(User user);

//会员注册

int userRegister(User user);

}

2 adminMapper

@Mapper

@Component

public interface AdminMapper{

//查询会员

List queryUser();

//新增会员

int addUser(User user);

//删除会员

int deleteUserById(int id);

//更新会员

int updateUser(User user);

//根据id查询一个会员

User queryUserById(int id);

//根据姓名查询一个会员

User queryUserByName(String name);

//login

Admin adminLogin(Admin admin);

//查询用户总数

int selectTotal();

// 分页

@Select("select * from gymms.user")

@Results({

// 用户信息,只要指定id列与属性的映射关系,其他列会自动封装(属性与列一致)

@Result(property = "id", column = "id"),

// 信息

@Result(property = "id", column = "id"),

@Result(property = "username", column = "username"),

@Result(property = "password", column = "password"),

@Result(property = "name", column = "name"),

@Result(property = "sex", column = "sex"),

@Result(property = "telephone", column = "telephone"),

@Result(property = "age", column = "age"),

@Result(property = "begintime", column = "begintime"),

@Result(property = "endtime", column = "endtime"),

@Result(property = "remainday", column = "remainday")

})

List findAll();

}

编写接口对应的 Mapper.xml 文件

1 userMapper.xml

/p>

PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

select remainday from gymms.user

where id = #{id}

select * from gymms.user

where id = #{id}

update gymms.user

set username = #{username},password = #{password}

where id = #{id}

select * from gymms.user

where username = #{username} and password = #{password}

insert into gymms.user(username,password,name,sex,telephone,age,begintime,endtime,remainday)

values (#{username},#{password},#{name},#{sex},#{telephone},#{age},#{begintime},#{endtime},#{remainday})

2 adminMapper.xml

/p>

PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

insert into gymms.user(username,password,name,sex,telephone,age,begintime,endtime,remainday)

values (#{username},#{password},#{name},#{sex},#{telephone},#{age},#{begintime},#{endtime},#{remainday})

delete from gymms.user where id=#{id}

update gymms.user

set username = #{username},password = #{password},name = #{name},sex = #{sex},telephone = #{telephone},

age = #{age},endtime = #{endtime},remainday = #{remainday}

where id = #{id}

select * from gymms.user

where id = #{id}

select * from gymms.user

where name = #{name}

SELECT * from gymms.user

select * from gymms.admin

where username = #{username} and password = #{password}

select count(*) from gymms.user

编写Service层的接口和实现类

1 userService

public interface UserService {

// 查询到期时间

Date queryDateById(int id);

//修改账号密码

int updateNP(User user);

//login

User userLogin(User user);

//通过id查询

User queryUserById(int id);

//会员注册

int userRegister(User user);

}

2 adminService

public interface AdminService {

//查询会员

List queryUser();

//新增会员

int addUser(User user);

//删除会员

int deleteUserById(int id);

//更新会员

int updateUser(User user);

//根据id查询一个会员

User queryUserById(int id);

//根据姓名查询一个会员

User queryUserByName(String name);

//login

Admin adminLogin(Admin admin);

//查询用户总数

int selectTotal();

// 分页

List findAll();

/**

* 分页查询

* @param pageNum 当然页

* @param pageSize 页大小

* @return 返回PageHelper提供的封装分页参数的PageInfo对象

*/

PageInfo findByPage(int pageNum, int pageSize);

}

3 userServiceImpl

public class UserServiceImpl implements UserService {

private UserMapper userMapper;

public void setUserMapper(UserMapper userMapper) {

this.userMapper = userMapper;

}

public Date queryDateById(int id) {

return userMapper.queryDateById(id);

}

public int updateNP(User user) {

return userMapper.updateNP(user);

}

public User userLogin(User user) {

return userMapper.userLogin(user);

}

public User queryUserById(int id) {

return userMapper.queryUserById(id);

}

public int userRegister(User user) {

return userMapper.userRegister(user);

}

}

4 adminServiceImpl

public class AdminServiceImpl implements AdminService {

private AdminMapper adminMapper;

public void setAdminMapper(AdminMapper adminMapper) {

this.adminMapper = adminMapper;

}

public List queryUser() {

return adminMapper.queryUser();

}

public int addUser(User user) {

return adminMapper.addUser(user);

}

public int deleteUserById(int id) {

return adminMapper.deleteUserById(id);

}

public int updateUser(User user) {

return adminMapper.updateUser(user);

}

public User queryUserById(int id) {

return adminMapper.queryUserById(id);

}

public User queryUserByName(String name) {

return adminMapper.queryUserByName(name);

}

public Admin adminLogin(Admin admin) {

return adminMapper.adminLogin(admin);

}

public int selectTotal() {

return adminMapper.selectTotal();

}

public List findAll() {

return adminMapper.findAll();

}

public PageInfo findByPage(int pageNum, int pageSize) {

PageHelper.startPage(pageNum, pageSize);

List list = adminMapper.findAll();

PageInfo pageInfo = new PageInfo<>(list);

return pageInfo;

}

}

Spring层

配置Spring整合MyBatis,我们这里数据源使用c3p0连接池;

编写Spring整合Mybatis的相关的配置文件;

spring-dao.xml

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context

https://www.springframework.org/schema/context/spring-context.xsd">

Spring整合service层

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd">

SpringMVC层

web.xml

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"

version="4.0">

DispatcherServlet

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:applicationContext.xml

1

DispatcherServlet

/

encodingFilter

org.springframework.web.filter.CharacterEncodingFilter

encoding

utf-8

encodingFilter

/*

15

spring-mvc.xml

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/mvc

https://www.springframework.org/schema/mvc/spring-mvc.xsd">

Spring配置整合文件,applicationContext.xml

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd">

Controller&视图层

UserController

package com.cc.controller;

import com.cc.pojo.User;

import com.cc.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Qualifier;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.ResponseBody;

import org.springframework.web.bind.annotation.RestController;

import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

@Controller

@RequestMapping("/user")

public class UserController {

@Autowired

@Qualifier("UserServiceImpl")

private UserService userService;

@RequestMapping("/toLogin")

public String toLoginUser(Model model,

HttpServletRequest request

) {

try {

String username = request.getParameter("username");

String password = request.getParameter("password");

System.out.println(username+" "+password);

User user =new User();

user.setUsername(username);

user.setPassword(password);

User users = userService.userLogin(user);

if (users.getId() > 0) {

// model.addAttribute("user", users);

model.addAttribute("user", users);

return "userMain";

}

} catch (Exception e) {

model.addAttribute("error","Wrong username or password!");

return "redirect:/";

}

return "redirect:/";

}

@ResponseBody

@RequestMapping("/toLogintest")

public String userLogin(String name,String pwd) {

String msg = "Wrong username or password!";

//模拟数据库中存在数据

if ((name != null) && (pwd != null)) {

// 从数据库检索是否存在该用户

User user = new User();

user.setUsername(name);

user.setPassword(pwd);

try {

User users = userService.userLogin(user);

if (users.getUsername().equals(name) && users.getPassword().equals(pwd)) {

msg = "Login Success";

}

return msg;

}catch (Exception e){}

return msg; //g

}

return msg;

}

@RequestMapping("/userBuy")

public String userBuyCard(Model model,int id) throws ParseException {

User user = userService.queryUserById(id);

System.out.println(user);

model.addAttribute("user",user );

return "userMall";

}

@RequestMapping("/userMianPage")

public String userMianPage(Model model,int id) throws ParseException {

User user = userService.queryUserById(id);

System.out.println(user);

model.addAttribute("user",user );

return "userMain";

}

// 跳转注册页面

@RequestMapping("/toUserRegister")

public String toAddPaper() {

return "register";

}

//注册

@RequestMapping("/userRegister")

public String registerUser(User user) throws ParseException {

SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

String date = sp.format(new Date());

user.setBegintime(date);

user.setEndtime(date);

user.setRemainday(0);

userService.userRegister(user);

return "redirect:/user/toLogin";

}

}

AdminController

package com.cc.controller;

import com.cc.pojo.Admin;

import com.cc.pojo.User;

import com.cc.service.AdminService;

import com.github.pagehelper.PageInfo;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Qualifier;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.servlet.ModelAndView;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

import java.util.List;

@Controller

@RequestMapping("/admin")

public class AdminController {

@Autowired

@Qualifier("AdminServiceImpl")

private AdminService adminService;

@RequestMapping("/toAddUser")

public String toAddPaper() {

return "register";

}

@RequestMapping("/addUser")

public String addPaper(User user) throws ParseException {

System.out.println(user);

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // 日期格式

Date date = dateFormat.parse(user.getBegintime()); // 指定日期

Calendar cl = Calendar.getInstance();

cl.setTime(date);

cl.add(Calendar.DATE, user.getRemainday());

String temp = "";

temp = dateFormat.format(cl.getTime());

user.setEndtime(temp);

adminService.addUser(user);

return "redirect:/admin/findByPage";

}

@RequestMapping("/toUpdateUser")

public String toUpdateUser(Model model, int id) {

User user = adminService.queryUserById(id);

System.out.println(user);

model.addAttribute("user",user );

return "updateUser";

}

@RequestMapping("/updateUser")

public String updateUser(Model model, User user) throws ParseException {

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 日期格式

Date date = dateFormat.parse(user.getBegintime()); // 指定日期

Calendar cl = Calendar.getInstance();

cl.setTime(date);

int allday = user.getRemainday()+user.getAddday();

cl.add(Calendar.DATE, allday);

String temp = "";

temp = dateFormat.format(cl.getTime());

user.setEndtime(temp);

user.setRemainday(allday);

adminService.updateUser(user);

User users = adminService.queryUserById(user.getId());

model.addAttribute("user", users);

return "redirect:/admin/findByPage";

}

@RequestMapping("/del/{userId}")

public String deleteBook(@PathVariable("userId") int id) {

adminService.deleteUserById(id);

return "redirect:/admin/findByPage";

}

@RequestMapping("/toaLogin")

public String toaLogin() {

return "/aLogin";

}

@RequestMapping("/aLogin")

public String toLoginUser(Admin admin) {

System.out.println(admin.getUsername()+admin.getPassword());

try {

Admin admins = adminService.adminLogin(admin);

if (admins.getId() > 0) {

// model.addAttribute("user", users);

return "redirect:/admin/findByPage";

}

}catch (Exception e){

return "/aLogin";

}

return "/aLogin";

}

@RequestMapping("/findAll")

public ModelAndView findAll() {

//1.1 调用service

List list = adminService.findAll();

//1.2 返回结果

ModelAndView mv = new ModelAndView();

mv.setViewName("order-list");

mv.addObject("list", list);

return mv;

}

@RequestMapping("/findByPage")

public String findByPage(Model model,

@RequestParam(defaultValue = "1") int pageNum,

@RequestParam(defaultValue = "11") int pageSize) {

PageInfo pageInfo = adminService.findByPage(pageNum, pageSize);

// PageInfo pageInfo = adminService.findByPage(pageNum, pageSize);

//1.1 调用service

//1.2 返回结果

model.addAttribute("list", pageInfo.getList());

model.addAttribute("pageInfo", pageInfo);

return "allUserPage";

}

@RequestMapping("/searchUser")

public String searchUser(Model model, String name) {

try {

User user = adminService.queryUserByName(name);

System.out.println(user);

model.addAttribute("user", user);

if (user.getName() == null) {

return "redirect:/admin/findByPage";

}

return "updateUser";

}catch (Exception e){

return "redirect:/admin/findByPage";

}

}

// 商城

@RequestMapping("/buy")

public String buyCard() throws ParseException {

return "mall";

}

}

视图层

详情见GitHub

拓展与展望

以下功能在以后可拓展开发

java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统_第13张图片

java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统_第14张图片

结束与总结

这个小Demo做了五六天,分页那里卡了接近两天,无数的坑等着踩。

期间也体会到了编程的乐趣,每天晚上都肝的快快乐乐。

所有代码放在GitHub供大家交流学习。

今天母亲节呀,祝我妈妈母亲节快乐! 晚安!

你可能感兴趣的:(java 健身会所_GitHub - idwyx/GymMS: 基于SSM的健身房管理系统)