寒假跟思途教育学了一周的Java实训课,学了一个简单的系统的制作,主要做了部门和员工,实际五天讲了只有部门一个类的增删查改。上完课后突发奇想,想总结一下几天学的东西,并写一个正式点的系统,于是选定学生信息管理系统。
首先自己做了一个word,把该实现的类,属性和方法都整理出来,具体现在想到的还很简单,主要涉及的依旧是增删查改,具体的文件如下。
编译器选用的是 STS (一种改进的Eclipese, 写框架很舒服)
应用的框架是 Springboot
前端的页面是用的 layui 的模板改的功能。
先放一个管理员的界面,目前管理员界面的基础功能代码已全部实现。
目前为止每个功能都可以实现,用时两天,第一天把所有的java后台代码写完,第二天开始改模板,然后前后端相连,其中觉得最麻烦的应该是前后端相连,因为Js代码有一点错就不能运行,还必须从网页上找错。
首先这是将管理员的java代码
Model 类
package com.sdau.student.admin.model;
public class Adminmodel {
private String code;
private String name;
private String pass;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
}
连接数据库的Mapper
package com.sdau.student.admin.mapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.sdau.student.admin.model.Adminmodel;
//数据层 操作数据库
@Mapper
public interface Adminmapper {
@Insert("insert into admin(code,name,pass) value(#{code},#{name},#{pass})")
public int insert(Adminmodel model);
@Delete("delete from admin where code=#{code}")
public int delete(Adminmodel model);
@Update("update admin set name=#{name},pass=#{pass} where code=#{code}")
public int update(Adminmodel model);
@Select("select * from admin where code=#{code}")
public Adminmodel select(Adminmodel model);
}
Service业务逻辑层
package com.sdau.student.admin.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sdau.student.admin.mapper.Adminmapper;
import com.sdau.student.admin.model.Adminmodel;
import com.sdau.student.student.model.Studentmodel;
import com.sdau.student.student.service.Studentservice;
//业务逻辑层
@Service
public class Adminservice {
@Autowired
private Adminmapper mapper;
@Autowired
private Studentservice service;
//注册用户,管理员不能自己实现
public int insert(Adminmodel model) {
//输入的code为空 返回3
String code = model.getCode();
if (code == null || "".equals(code)) {
return 3;
}
// 数据库中存在code 不能插入 返回2
//插入返回1;
Adminmodel m0 = new Adminmodel();
m0.setCode(code);
Adminmodel dbp = mapper.select(m0);
if (dbp == null) {
return mapper.insert(model);
} else {
return 2;
}
}
//删除用户,管理员不能自己实现
public int delete(Adminmodel model) {
return mapper.delete(model);
}
//管理员更改个人信息操作
public int update(Adminmodel model) {
Adminmodel m0=new Adminmodel();
m0.setCode(model.getCode());
Adminmodel aa=mapper.select(m0);
if(aa==null) {
return 2;
}else {
return mapper.update(model);
}
}
//管理员登录操作
public int login(Adminmodel model) {
Adminmodel m0=new Adminmodel();
m0.setCode(model.getCode());
Adminmodel aa=mapper.select(m0);
//null 为没有数据 不能登录
if(aa==null) {
return 0;
}
//返回1 登录成功
//返回2 密码错误
if(aa.getPass().equals(model.getPass())) {
return 1;
}else {
return 2;
}
}
}
Controller 控制层:
package com.sdau.student.admin.controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.github.pagehelper.PageInfo;
import com.sdau.student.admin.model.Adminmodel;
import com.sdau.student.admin.service.Adminservice;
import com.sdau.student.course.model.Coursemodel;
import com.sdau.student.course.service.Courseservice;
import com.sdau.student.score.model.Scoremodel;
import com.sdau.student.score.service.Scoreservice;
import com.sdau.student.student.model.Studentmodel;
import com.sdau.student.student.service.Studentservice;
//控制层 (接受请求,获取参数,封装对象,调用方法,返回结果)
@Controller
@RequestMapping("admin")
public class Admincontroller {
@Autowired
private Adminservice service;
@Autowired
private Courseservice service1;
@Autowired
private Studentservice service3;
@Autowired
private Scoreservice service4;
@RequestMapping("/test")
@ResponseBody
public String test() {
return "123456";
}
@RequestMapping("update")
@ResponseBody
public Map update(Adminmodel model) {
Map map=new HashMap<>();
map.put("code", service.update(model));
return map;
}
@RequestMapping("login")
@ResponseBody
public Map login(Adminmodel model){
Map map=new HashMap<>();
map.put("code",service.login(model));
return map;
}
//对课程进行操作
//插入课程
@RequestMapping("addcourse")
@ResponseBody
public Map addcourse(Coursemodel model){
Map map=new HashMap<>();
map.put("code", service1.addcourse(model));
return map;
}
//删除课程
@RequestMapping("deletecourse")
@ResponseBody
public Map deletecourse(Coursemodel model){
Map map=new HashMap<>();
map.put("code", service1.deletecourse(model));
return map;
}
//修改课程
@RequestMapping("updatecourse")
@ResponseBody
public Map update(Coursemodel model){
Map map=new HashMap<>();
map.put("code", service1.update(model));
return map;
}
//通过课程号查找课程
@RequestMapping("selectbycode")
@ResponseBody
public Map selectbycode(Coursemodel model){
Map map=new HashMap<>();
map.put("code", service1.selectbycode(model));
return map;
}
//根据课程名查找课程
@RequestMapping("selectbyname")
@ResponseBody
public Map selectbyname(Coursemodel model){
Map map=new HashMap<>();
map.put("code", service1.selectbyname(model));
return map;
}
//根据老师查找课程
@RequestMapping("selectbyteacher")
@ResponseBody
public Map selectbyteacher(Coursemodel model){
Map map=new HashMap<>();
map.put("code", service1.selectbyteacher(model));
return map;
}
//对学生操作
//增加学生
@RequestMapping("addstu")
@ResponseBody
public Map addstu(Studentmodel model){
Map map=new HashMap<>();
map.put("code", service3.addstu(model));
return map;
}
//修改学生密码
@RequestMapping("updatepass")
@ResponseBody
public Map updatepass(Studentmodel model){
Map map=new HashMap<>();
map.put("code", service3.updatepass(model));
return map;
}
//修改学生基本信息
@RequestMapping("updateinfo")
@ResponseBody
public Map updateinfo(Studentmodel model){
Map map=new HashMap<>();
map.put("code", service3.updateinfo(model));
return map;
}
//删除学生
@RequestMapping("deletestu")
@ResponseBody
public Map deletestu(Studentmodel model){
Map map=new HashMap<>();
map.put("code", service3.deletestu(model));
return map;
}
//查询学生
//通过学号查找学生
@RequestMapping("selectstubycode")
@ResponseBody
public Map selectbycode(Studentmodel model){
Map map=new HashMap<>();
map.put("code", service3.selectbycode(model));
return map;
}
//根据学生姓名查找学生
@RequestMapping("selectstubyname")
@ResponseBody
public Map selectstubyname(Studentmodel model){
Map map=new HashMap<>();
map.put("code", service3.selectbyname(model));
return map;
}
//根据专业查找学生
@RequestMapping("selectstubymajor")
@ResponseBody
public Map selectstubymajor(Studentmodel model){
Map map=new HashMap<>();
map.put("code", service3.selectbymajor(model));
return map;
}
//课程分数操作
//添加学生成绩
@RequestMapping("addscore")
@ResponseBody
public Map addscore(Scoremodel model){
Map map=new HashMap<>();
map.put("code",service4.insert(model));
return map;
}
//删除学生课程成绩
@RequestMapping("deletescore")
@ResponseBody
public Map deletescore(Scoremodel model){
Map map=new HashMap<>();
map.put("code",service4.delete(model));
return map;
}
//查询学生成绩
@RequestMapping("selectstuscore")
@ResponseBody
public Map selectstu(Scoremodel model){
Map map=new HashMap<>();
map.put("code",service4.selectstu(model));
return map;
}
//查询课程成绩
@RequestMapping("selectcoursescore")
@ResponseBody
public Map selectcourse(Scoremodel model){
Map map=new HashMap<>();
map.put("code",service4.selectcourse(model));
return map;
}
@RequestMapping("selectscore")
@ResponseBody
public Map selectscore(Scoremodel model){
Map map=new HashMap<>();
map.put("code",service4.select(model));
return map;
}
//修改学生成绩
@RequestMapping("updatescore")
@ResponseBody
public Map updatecourse(Scoremodel model){
Map map=new HashMap<>();
map.put("code",service4.update(model));
return map;
}
@RequestMapping("selectpage")
@ResponseBody
public Map selectPage(Studentmodel model, int page,int limit) {
PageInfoinfo=service3.selectPage(model, page, limit);
Map res = new HashMap<>();
res.put("data", info.getList());
res.put("count", info.getTotal());
res.put("code", 0);
return res;
}
@RequestMapping("selectpage1")
@ResponseBody
public Map selectPage1(Studentmodel model, int page,int limit) {
PageInfoinfo=service3.selectPage1(model, page, limit);
Map res = new HashMap<>();
res.put("data", info.getList());
res.put("count", info.getTotal());
res.put("code", 0);
return res;
}
@RequestMapping("selectpage2")
@ResponseBody
public Map selectPage2(Studentmodel model, int page,int limit) {
PageInfoinfo=service3.selectPage2(model, page, limit);
Map res = new HashMap<>();
res.put("data", info.getList());
res.put("count", info.getTotal());
res.put("code", 0);
return res;
}
//课程名
@RequestMapping("selectpage3")
@ResponseBody
public Map selectPage3(Coursemodel model, int page,int limit) {
PageInfoinfo=service1.selectPage(model, page, limit);
Map res = new HashMap<>();
res.put("data", info.getList());
res.put("count", info.getTotal());
res.put("code", 0);
return res;
}
//课程号
@RequestMapping("selectpage4")
@ResponseBody
public Map selectPage4(Coursemodel model, int page,int limit) {
PageInfoinfo=service1.selectPage1(model, page, limit);
Map res = new HashMap<>();
res.put("data", info.getList());
res.put("count", info.getTotal());
res.put("code", 0);
return res;
}
//任课教师
@RequestMapping("selectpage5")
@ResponseBody
public Map selectPage5(Coursemodel model, int page,int limit) {
PageInfoinfo=service1.selectPage2(model, page, limit);
Map res = new HashMap<>();
res.put("data", info.getList());
res.put("count", info.getTotal());
res.put("code", 0);
return res;
}
@RequestMapping("selectpage6")
@ResponseBody
public Map selectPage6(Scoremodel model, int page,int limit) {
PageInfoinfo=service4.selectPage(model, page, limit);
Map res = new HashMap<>();
res.put("data", info.getList());
res.put("count", info.getTotal());
res.put("code", 0);
return res;
}
@RequestMapping("selectpage7")
@ResponseBody
public Map selectPage7(Scoremodel model, int page,int limit) {
PageInfoinfo=service4.selectPage1(model, page, limit);
Map res = new HashMap<>();
res.put("data", info.getList());
res.put("count", info.getTotal());
res.put("code", 0);
return res;
}
}
前端代码比较复杂且比较多,只放几个主要应用的代码:
主页面:
<%@ page language="java" contentType="text/html; charset=Utf-8"
pageEncoding="Utf-8"%>
管理员操作页面
增加学生页面:
<%@ page language="java" contentType="text/html; charset=Utf-8"
pageEncoding="Utf-8"%>
添加学生信息
根据姓名查询页面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
根据学号查询学生信息
修改信息页面(放一个修改密码)
<%@ page language="java" contentType="text/html; charset=Utf-8"
pageEncoding="Utf-8"%>
Insert title here
接下来几天会抽时间写一下其余的几个页面,具体问题写完后再考虑添加一些特殊功能。