Java毕业设计实战之校园一卡通系统的实现
作者:OldWinePot 时间:2022-11-26 06:32:56
一、项目简述(+需求文档+PPT)
功能:卡管理,卡消费,卡充值,图书借阅,消费,记录,注销等等功能。
二、项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP + Servlet + html+ css + JavaScript + JQuery + Ajax 等等
用户管理操作控制层:
/**
* 用户管理操作
*/
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
/**
* 用户添加页面
* @return
*/
@GetMapping("/add")
public String create() {
return "user/add";
}
/**
* 用户添加操作
* @param user
* @return
*/
@PostMapping("/add")
@ResponseBody
public Map<String, Object> add(@RequestBody User user) {
if(StringUtils.isEmpty(user.getUserName())){
return MapControl.getInstance().error("请填写用户名").getMap();
}
if(StringUtils.isEmpty(user.getName())){
return MapControl.getInstance().error("请填写名称").getMap();
}
if(StringUtils.isEmpty(user.getUserPwd())){
return MapControl.getInstance().error("请填写密码").getMap();
}
int result = userService.create(user);
if (result <= 0) {
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
/**
* 根据id删除
* @param id
* @return
*/
@PostMapping("/delete/{id}")
@ResponseBody
public Map<String, Object> delete(@PathVariable("id") Integer id) {
int result = userService.delete(id);
if (result <= 0) {
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
//批量删除
@PostMapping("/delete")
@ResponseBody
public Map<String, Object> delete(String ids) {
int result = userService.delete(ids);
if (result <= 0) {
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
/**
* 编辑用户信息操作
* @param user
* @return
*/
@PostMapping("/edit")
@ResponseBody
public Map<String, Object> edit(@RequestBody User user) {
if(StringUtils.isEmpty(user.getUserName())){
return MapControl.getInstance().error("请填写用户名").getMap();
}
if(StringUtils.isEmpty(user.getName())){
return MapControl.getInstance().error("请填写名称").getMap();
}
if(StringUtils.isEmpty(user.getUserPwd())){
return MapControl.getInstance().error("请填写密码").getMap();
}
int result = userService.update(user);
if (result <= 0) {
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
/**
* 根据id查询,跳转修改页面
* @param id
* @param modelMap
* @return
*/
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Integer id, ModelMap modelMap) {
User user = userService.detail(id);
modelMap.addAttribute("user", user);
return "user/edit";
}
//查询所有
@PostMapping("/query")
@ResponseBody
public Map<String, Object> query(@RequestBody User user) {
List<User> list = userService.query(user);
Integer count = userService.count(user);
return MapControl.getInstance().success().page(list, count).getMap();
}
//跳转列表页面
@GetMapping("/list")
public String list() {
return "user/list";
}
}
登录控制层:
@Controller
public class LoginController {
@Autowired
private UserService userService;
@Autowired
private TeacherService teacherService;
@Autowired
private StudentService studentService;
//跳转登录页面
@GetMapping("/login")
public String login() {
return "login";
}
//登录操作
@PostMapping("/login")
@ResponseBody
public Map<String, Object> login(String userName, String password, String captcha, String type, HttpSession session) {
//判断用户名、密码、用户类型、验证码是否为空
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password) || StringUtils.isEmpty(captcha) || StringUtils.isEmpty(type)) {
return MapControl.getInstance().error("用户名或密码不能为空").getMap();
}
//获取系统生成的验证码
String _captcha = (String) session.getAttribute("captcha");
//先判断验证码是否正确
if (!(captcha.toLowerCase()).equals(_captcha.toLowerCase())) {
//验证码错误
return MapControl.getInstance().error("验证码错误").getMap();
}
//判断用户类型
if ("1".equals(type)) { //管理员验证登录
User user = userService.login(userName, MD5Utils.getMD5(password)); //对密码进行加密处理,因为数据库中存储的是加密后的密码
if (user != null) {
session.setAttribute("user", user);
session.setAttribute("type", 1);
return MapControl.getInstance().success().add("data", user).getMap();
} else {
return MapControl.getInstance().error("用户名或密码错误").getMap();
}
}
if ("2".equals(type)) { //老师验证登录
Teacher teacher = teacherService.login(userName, MD5Utils.getMD5(password));
if (teacher != null) {
session.setAttribute("user", teacher);
session.setAttribute("type", "2");
return MapControl.getInstance().success().add("data", teacher).getMap();
} else {
return MapControl.getInstance().error("用户名或密码错误").getMap();
}
}
if ("3".equals(type)) { //学生验证登录
Student student = studentService.login(userName, MD5Utils.getMD5(password));
if (student != null) {
session.setAttribute("user", student);
session.setAttribute("type", "3");
return MapControl.getInstance().success().add("data", student).getMap();
} else {
return MapControl.getInstance().error("用户名或密码错误").getMap();
}
}
return MapControl.getInstance().getMap();
}
}
生成验证码:
@Controller
@RequestMapping("/captcha")
public class CaptchaController {
private char[] codeSequence = {'A', '1', 'B', 'C', '2', 'D', '3', 'E', '4', 'F', '5', 'G', '6', 'H', '7', 'I', '8', 'J',
'K', '9', 'L', '1', 'M', '2', 'N', 'P', '3', 'Q', '4', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z'};
@RequestMapping("/code")
public void getCode(HttpServletResponse response, HttpSession session) throws IOException {
int width = 80;
int height = 37;
Random random = new Random();
//设置response头信息
//禁止缓存
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
//生成缓冲区image类
BufferedImage image = new BufferedImage(width, height, 1);
//产生image类的Graphics用于绘制操作
Graphics g = image.getGraphics();
//Graphics类的样式
g.setColor(this.getColor(200, 250));
g.setFont(new Font("Times New Roman", 0, 28));
g.fillRect(0, 0, width, height);
//绘制干扰线
for (int i = 0; i < 40; i++) {
g.setColor(this.getColor(130, 200));
int x = random.nextInt(width);
int y = random.nextInt(height);
int x1 = random.nextInt(12);
int y1 = random.nextInt(12);
g.drawLine(x, y, x + x1, y + y1);
}
//绘制字符
String strCode = "";
for (int i = 0; i < 4; i++) {
String rand = String.valueOf(codeSequence[random.nextInt(codeSequence.length)]);
strCode = strCode + rand;
g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
g.drawString(rand, 13 * i + 6, 28);
}
//将字符保存到session中用于前端的验证
session.setAttribute("captcha", strCode.toLowerCase());
g.dispose();
ImageIO.write(image, "JPEG", response.getOutputStream());
response.getOutputStream().flush();
}
public Color getColor(int fc, int bc) {
Random random = new Random();
if (fc > 255)
fc = 255;
if (bc > 255)
bc = 255;
int r = fc + random.nextInt(bc - fc);
int g = fc + random.nextInt(bc - fc);
int b = fc + random.nextInt(bc - fc);
return new Color(r, g, b);
}
}
来源:https://blog.csdn.net/pastclouds/article/details/121883590
标签:Java,校园一卡通系统,毕业设计,大作业
0
投稿
猜你喜欢
Flutter 自定义Drawer 滑出位置的大小实例代码详解
2021-09-18 23:18:19
Android 控制wifi 相关操作实例
2023-09-08 20:35:49
JavaWeb页面中防止点击Backspace网页后退情况
2023-11-10 10:36:36
Android按钮按下的时候改变颜色实现方法
2021-09-24 20:15:39
mybatis-plus与JPA混合的使用方式
2022-06-24 02:10:25
详解C# 不能用于文件名的字符
2023-03-05 07:44:45
带你了解C++的数组与函数
2023-12-10 20:44:18
详解Spring Boot加载properties和yml配置文件
2023-11-24 07:14:09
Java8新特性Stream流实例详解
2023-05-04 12:55:05
C++集体数据交换实现示例讲解
2023-12-17 11:35:07
c# AcceptEx与完成端口(IOCP)结合的示例
2023-07-29 01:46:24
SpringBoot框架集成ElasticSearch实现过程示例详解
2023-02-02 08:44:05
Springboot一个注解搞定返回参数key转换功能
2022-06-21 00:11:24
java 实现KMP算法
2022-09-14 15:44:40
C语言内存操作函数详解
2021-09-01 01:50:36
Android调用相机并将照片存储到sd卡上实现方法
2023-11-06 00:41:41
SpringBoot定时任务两种(Spring Schedule 与 Quartz 整合 )实现方法
2023-11-01 16:03:39
Java并发编程之Java内存模型
2023-08-17 23:06:10
Android仿滴滴出行验证码输入框功能实例代码
2022-12-08 05:15:49
Android开发实现删除联系人通话记录的方法
2022-10-26 16:56:49