基于javaweb+mysql的ssm+maven学生成绩管理系统(java+jsp+maven+ssm+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
学生成绩的增删改查管理
技术框架
JavaBean MVC JSP SSM(Spring SpringMVC MyBatis) Maven MySQL Bootstrap JavaScript
基于javaweb+mysql的SSM+Maven学生成绩管理系统(java+jsp+maven+ssm+mysql)
@Service
public class StuServiceImpl implements StudentService {
@Autowired
private StudentMapper studentMapper;
//查询所有
@Override
public List<Student> selectStudentAll(ParamsStu params) {
if (params.getPageNum() == 0) {
params.setPageNum(1);
}
PageHelper.startPage(params.getPageNum(), params.getPageSize());
//pageNum当前页,pageSize 每页条数
return studentMapper.selectStudentAll(params);
}
@Override
public void deleteStudent(int id) {
studentMapper.deleteStudent(id);
}
@Override
public Student updateStudentEdit(int id) {
return studentMapper.updateStudentEdit(id);
}
@Override
public void upadateStudent(Student student) {
studentMapper.upadateStudent(student);
}
@Override
public void insertStudent(Student student) {
studentMapper.insertStudent(student);
}
}
if (name == "") {
alert("学生名不能为空!");
return false;
}
if (classid == "") {
alert("班级编号不能为空!");
return false;
}
if (teacher == "") {
alert("老师姓名不能为空!");
return false;
}
if (score == "" || !/^\d+(\.0*)?$/.test(score)) {
alert("成绩必须为数字");
return false;
}
if (subject == "") {
alert("学课不能为空!");
return false;
}
return true;
}
</script>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.demo.mapper.StudentMapper">
<resultMap id="resultMapStudent" type="Student" >
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="classid" column="classid"/>
<result property="teacher" column="teacher"/>
<result property="score" column="score" />
<result property="subject" column="subject" />
</resultMap>
<select id="selectStudentAll" parameterType="ParamsStu" resultMap="resultMapStudent">
select * from student
<where>
<if test="name!=null and name!=''">
name like concat('%',#{name},'%')
</if>
}
@Override
public void insertStudent(Student student) {
studentMapper.insertStudent(student);
}
}
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public User get(String username, String password) {
Map<String, Object> params = new HashMap<>();
params.put("username", username);
params.put("password", password);
List<User> list = this.userMapper.findAllSplit(params);
return list.isEmpty() ? null : list.get(0);
}
}
public class User {
private Integer id;
private String username;
private String password;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
<h1 style="text-align: center;">学生成绩管理系统</h1>
<form action="login" method="post" onsubmit="return check()">
<div class="login">
<div class="login-top">
登录
</div>
<div class="login-center clearfix">
<div class="login-center-img"><img src="img/name.png"/></div>
<div class="login-center-input">
<input type="text" id="username" name="username" value="" placeholder="用户名"
onfocus="this.placeholder=''" onblur="this.placeholder='用户名'"/>
</div>
</div>
<br>
<br>
<br>
<div class="login-center clearfix">
<div class="login-center-img"><img src="img/password.png"/></div>
<div class="login-center-input">
<input type="password" id="password" name="password" value="" placeholder="密码"
onfocus="this.placeholder=''" onblur="this.placeholder='密码'"/>
</div>
</div>
<br>
<br>
<br>
<button type="submit" class="login-button">登陆</button>
</div>
</form>
</body>
<script type="text/javascript">
//提交之前进行检查,如果return false,则不允许提交
function check() {
//根据ID获取值
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if (username == "") {
alert("用户名不能为空");
return false;
}
if (password == "") {
alert("密码不能为空");
return false;
}
return true;
}
</script>
</html>
}
return true;
}
</script>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>修改的编辑页面</title>
<script type="text/javascript"
src="https://cdn.staticfile.org/twitter-bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css"
href="https://cdn.staticfile.org/twitter-bootstrap/3.3.4/css/bootstrap.min.css">
</head>
<body>
<div class="col-xs-3 col-md-offset-4">
<br/><br/><br/>
<form role="form" action="${pageContext.request.contextPath}/updateStudent">
<div class="form-group">
<label for="name">学生姓名</label>
<input type="text" class="form-control" name="name" id="name" value="${student.name}" placeholder="请输入学生姓名">
</div>
<div class="form-group">
<label for="name">班级编号</label>
<input type="text" class="form-control" name="classid" id="classid" value="${student.classid}"
placeholder="请输入班级编号">
</div>
<div class="form-group">
<label for="name">教师姓名</label>
<input type="text" class="form-control" name="teacher" id="teacher" value="${student.teacher}"
placeholder="请输入教师姓名">
</div>
<div class="form-group">
<label for="name">学生成绩</label>
<input type="text" class="form-control" name="score" id="score" value="${student.score}"
placeholder="请输入学生成绩">
</div>
public interface StudentMapper {
//查询所有
public List<Student> selectStudentAll(ParamsStu params);
//根据id删除学生
void deleteStudent(int id);
//根据id查询学生,然后进入编辑页面 展示信息准备修改
Student updateStudentEdit(int id);
//修改编辑页面,提交执行修改
void upadateStudent(Student student);
//添加学生
void insertStudent(Student student);
}
public interface StudentService {
//查询所有
public List<Student> selectStudentAll(ParamsStu params);
void deleteStudent(int id);
Student updateStudentEdit(int id);
void upadateStudent(Student student);
void insertStudent(Student student);
}
public interface UserMapper {
List<User> findAllSplit(Map<String, Object> params);
position: relative;
}
.login-center-input input {
z-index: 2;
transition: all 0.5s;
padding-left: 10px;
color: #333333;
width: 100%;
height: 30px;
border: 0;
border-bottom: 1px solid #cccccc;
border-top: 1px solid #ffffff;
border-left: 1px solid #ffffff;
border-right: 1px solid #ffffff;
box-sizing: border-box;
outline: none;
position: relative;
}
.login-center-input input:focus {
border: 1px solid dodgerblue;
}
.login-center-input input:focus ~
.login-center-input-text {
top: 0;
z-index: 3;
opacity: 1;
margin-top: -15px;
}
.login-button {
cursor: pointer;
width: 250px;
text-align: center;
height: 40px;
line-height: 40px;
background-color: dodgerblue;
border: none;
margin: 0 auto;
margin-top: 50px;
color: white;
display: block;
private String classid;
private String teacher;
private Integer score;
private String subject;
public Student() {
}
public Student(Integer id, String name, String classid, String teacher, Integer score) {
this.id = id;
this.name = name;
this.classid = classid;
this.teacher = teacher;
this.score = score;
}
public Student(String name, String classid, String teacher, Integer score) {
this.name = name;
this.classid = classid;
this.teacher = teacher;
this.score = score;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getClassid() {
return classid;
}
public void setClassid(String classid) {
this.classid = classid;
}
</div>
<br>
<br>
<br>
<button type="submit" class="login-button">登陆</button>
</div>
</form>
</body>
<script type="text/javascript">
//提交之前进行检查,如果return false,则不允许提交
function check() {
//根据ID获取值
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if (username == "") {
alert("用户名不能为空");
return false;
}
if (password == "") {
alert("密码不能为空");
return false;
}
return true;
}
</script>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>修改的编辑页面</title>
<script type="text/javascript"
src="https://cdn.staticfile.org/twitter-bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css"
href="https://cdn.staticfile.org/twitter-bootstrap/3.3.4/css/bootstrap.min.css">
</head>
<body>
<div class="col-xs-3 col-md-offset-4">
<br/><br/><br/>
<form role="form" action="${pageContext.request.contextPath}/updateStudent">
<div class="form-group">
@Controller
public class LoginController {
@Autowired
private UserService userService;
@RequestMapping("login")
public void login(HttpServletRequest request, HttpServletResponse response) throws Exception {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
HttpSession session = request.getSession();
// boolean flag = "admin".equals(request.getParameter("username")) && "123456".equals(request.getParameter("password"));//模拟数据库登录
User user = userService.get(request.getParameter("username"), request.getParameter("password"));
if (user != null) {
session.setAttribute("msg", "Login Success!!!");
session.setAttribute("url", "/selectStudentAll");
} else {
session.setAttribute("msg", "username or password was wrong!");
session.setAttribute("url", "/login.jsp");
}
request.getRequestDispatcher("/forward.jsp").forward(request, response);
}
}
public void setName(String name) {
this.name = name;
}
public String getClassid() {
return classid;
}
public void setClassid(String classid) {
this.classid = classid;
}
public String getTeacher() {
return teacher;
}
public void setTeacher(String teacher) {
this.teacher = teacher;
}
public Integer getScoreFrom() {
return scoreFrom;
}
public void setScoreFrom(Integer scoreFrom) {
this.scoreFrom = scoreFrom;
}
public Integer getScoreTo() {
return scoreTo;
}
public void setScoreTo(Integer scoreTo) {
this.scoreTo = scoreTo;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
</div>
<br>
<br>
<br>
<button type="submit" class="login-button">登陆</button>
</div>
</form>
</body>
<script type="text/javascript">
//提交之前进行检查,如果return false,则不允许提交
function check() {
//根据ID获取值
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if (username == "") {
alert("用户名不能为空");
return false;
}
if (password == "") {
alert("密码不能为空");
return false;
}
return true;
}
</script>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>修改的编辑页面</title>
<script type="text/javascript"
src="https://cdn.staticfile.org/twitter-bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css"
href="https://cdn.staticfile.org/twitter-bootstrap/3.3.4/css/bootstrap.min.css">
</head>
<body>
<div class="col-xs-3 col-md-offset-4">
<br/><br/><br/>
session.setAttribute("msg", "Login Success!!!");
session.setAttribute("url", "/selectStudentAll");
} else {
session.setAttribute("msg", "username or password was wrong!");
session.setAttribute("url", "/login.jsp");
}
request.getRequestDispatcher("/forward.jsp").forward(request, response);
}
}
@Service
public class StuServiceImpl implements StudentService {
@Autowired
private StudentMapper studentMapper;
//查询所有
@Override
public List<Student> selectStudentAll(ParamsStu params) {
if (params.getPageNum() == 0) {
params.setPageNum(1);
}
PageHelper.startPage(params.getPageNum(), params.getPageSize());
//pageNum当前页,pageSize 每页条数
return studentMapper.selectStudentAll(params);
}
@Override
public void deleteStudent(int id) {
studentMapper.deleteStudent(id);
}
<if test="classid!=null and classid!=''">
and classid like concat('%',#{classid},'%')
</if>
<if test="teacher!=null and teacher!=''">
and teacher like concat('%',#{teacher},'%')
</if>
<if test="scoreFrom!=null and scoreFrom!=''">
and score >= #{scoreFrom}
</if>
<if test="scoreTo!=null and scoreTo!=''">
and score <= #{scoreTo}
</if>
<if test="subject!=null and subject!=''">
and subject like concat('%',#{subject},'%')
</if>
</where>
</select>
<!--删除-->
<delete id="deleteStudent">
delete from student where id=#{id}
</delete>
<!--查询一条:为修改准备-->
<select id="updateStudentEdit" resultMap="resultMapStudent">
select * from student where id=#{id}
</select>
<!--修改-->
<update id="upadateStudent" parameterType="Student">
update student set
name=#{name},classid=#{classid},teacher=#{teacher},score=#{score},subject=#{subject}
where id=#{id}
</update>
<!--添加-->
<insert id="insertStudent" parameterType="Student">
insert into student(name,classid,teacher,score,subject)
values (#{name},#{classid},#{teacher},#{score},#{subject})
</insert>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.demo.mapper.UserMapper">
<resultMap id="BaseResultMap" type="com.demo.entity.User">
<result column="id" property="id"/>
<result column="username" property="username"/>
<result column="password" property="password"/>
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public User get(String username, String password) {
Map<String, Object> params = new HashMap<>();
params.put("username", username);
params.put("password", password);
List<User> list = this.userMapper.findAllSplit(params);
return list.isEmpty() ? null : list.get(0);
}
}
public class User {
private Integer id;
private String username;
private String password;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
@Override
public void upadateStudent(Student student) {
studentMapper.upadateStudent(student);
}
@Override
public void insertStudent(Student student) {
studentMapper.insertStudent(student);
}
}
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public User get(String username, String password) {
Map<String, Object> params = new HashMap<>();
params.put("username", username);
params.put("password", password);
List<User> list = this.userMapper.findAllSplit(params);
return list.isEmpty() ? null : list.get(0);
}
}
public class User {
private Integer id;
private String username;
private String password;
public Integer getId() {
return id;
@Service
public class StuServiceImpl implements StudentService {
@Autowired
private StudentMapper studentMapper;
//查询所有
@Override
public List<Student> selectStudentAll(ParamsStu params) {
if (params.getPageNum() == 0) {
params.setPageNum(1);
}
PageHelper.startPage(params.getPageNum(), params.getPageSize());
//pageNum当前页,pageSize 每页条数
return studentMapper.selectStudentAll(params);
}
@Override
public void deleteStudent(int id) {
studentMapper.deleteStudent(id);
}
@Override
public Student updateStudentEdit(int id) {
return studentMapper.updateStudentEdit(id);
}
@Override
public void upadateStudent(Student student) {
studentMapper.upadateStudent(student);
public class Student {
private Integer id;
private String name;
private String classid;
private String teacher;
private Integer score;
private String subject;
public Student() {
}
public Student(Integer id, String name, String classid, String teacher, Integer score) {
this.id = id;
this.name = name;
this.classid = classid;
this.teacher = teacher;
this.score = score;
}
public Student(String name, String classid, String teacher, Integer score) {
this.name = name;
this.classid = classid;
this.teacher = teacher;
this.score = score;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}