控制台没有报错,但是无法更新数据
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> <html> <head> <meta charset="utf-8"> <title>欢迎来到苏州科技大学教师后台管理系统</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="/css/theme.css"> <link rel="stylesheet" type="text/css" href="/css/admin-forms.css"> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script> <![endif]--> </head> <body class="admin-validation-page" data-spy="scroll" data-target="#nav-spy" data-offset="200"> <div id="main"> <header class="navbar navbar-fixed-top navbar-shadow"> <div class="navbar-branding"> <a class="navbar-brand" href="/index.html"> <H3>苏州科技大学后台管理系统</H3> </a> <span id="toggle_sidemenu_l" class="ad ad-lines"></span> </div> </header> <aside id="sidebar_left" class="nano nano-light affix"> <div class="sidebar-left-content nano-content"> <header class="sidebar-header"> <div class="sidebar-widget author-widget"> <div class="media"> <a class="media-left" href="#"> <img src="/images/head.jpg" class="img-responsive"> </a> <div class="media-body"> <div class="media-author">杜景龙</div> <div class="media-links"> <a href="login.html">退出</a> </div> </div> </div> </div> <div class="sidebar-widget search-widget hidden"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-search"></i> </span> <input type="text" id="sidebar-search" class="form-control" placeholder="Search..."> </div> </div> </header> <ul class="nav sidebar-menu"> <li class="sidebar-label pt20">学生信息</li> <li class="active"> <a href="${pageContext.request.contextPath}/index"> <span class="glyphicon glyphicon-book"></span> <span class="sidebar-title">现有学生</span> </a> </li> <li> <a href="${pageContext.request.contextPath}/addusers.jsp"> <span class="glyphicon glyphicon-home"></span> <span class="sidebar-title" >添加学生</span> </a> </li> <li class="sidebar-label pt20">课程管理</li> <li class="active"> <a href="catalog_list.html"> <span class="glyphicon glyphicon-book"></span> <span class="sidebar-title">学生成绩</span> </a> </li> <li class="active"> <a href="catalog_list.html"> <span class="glyphicon glyphicon-book"></span> <span class="sidebar-title">乔睿琪</span> </a> </li> <li class="active"> <a href="catalog_list.html"> <span class="glyphicon glyphicon-book"></span> <span class="sidebar-title">于佳民</span> </a> </li> <li> <a href="catalog_add.html"> <span class="glyphicon glyphicon-home"></span> <span class="sidebar-title">添加课程</span> </a> </li> </ul> <div class="sidebar-toggle-mini"> <a href="login.html"> <span class="fa fa-sign-out"></span> </a> </div> </div> </aside> <section id="content_wrapper"> <section id="content" class="table-layout animated fadeIn"> <div class="tray tray-center"> <div class="content-header"> <h2> 学生管理</h2> <p class="lead"></p> </div> <div class="admin-form theme-primary mw1000 center-block" style="padding-bottom: 175px;"> <div class="panel heading-border"> <div class="panel-menu"> <div class="row"> <div class="hidden-xs hidden-sm col-md-3"> <div class="btn-group"> <button type="button" class="btn btn-default light"> <i class="fa fa-trash"></i> </button> <button type="button" class="btn btn-default light"> <i class="fa fa-plus" onclick="javascript:window.location.href='cake_add.html';"></i> </button> </div> </div> <div class="col-xs-12 col-md-9 text-right"> <form action="cake_list.html" method="post"> 共35条 1/2 <div class="btn-group"> <button type="submit" name="pageNum" value="0" class="btn btn-default light"> <i class="fa fa-chevron-left"></i> </button> <button type="submit" name="pageNum" value="2" class="btn btn-default light"> <i class="fa fa-chevron-right"></i> </button> </div> </form> </div> </div> </div> <div class="panel-body pn"> <table id="message-table" class="table admin-form theme-warning tc-checkbox-1"> <thead> <tr class=""> <th class="hidden-xs">学生编号</th> <th class="hidden-xs">学生姓名</th> <th class="hidden-xs">课程名称</th> <th class="hidden-xs">年级</th> <th class="hidden-xs">成绩</th> </tr> </thead> </table> </div> <tbody> <c:forEach var="user" items="${gradeList}"> <tr class="message-unread"> <td class="hidden-xs"> ${user.uid} </td> <td >${user.username}</td> <td >${user.courseid}</td> <td >${user.coursename}</td> <td >${user.grade}</td> <td>${user.chengji}</td> <td><a href="${pageContext.request.contextPath}/Gradedetail?courseid=${user.courseid}">修改</a></td> </td> </tr> </c:forEach> </tbody> </div> </div> </div> </section> </section> </div> <style> /* demo page styles */ body { min-height: 2300px; } .content-header b, .admin-form .panel.heading-border:before, .admin-form .panel .heading-border:before { transition: all 0.7s ease; } /* responsive demo styles */ @media (max-width: 800px) { .admin-form .panel-body { padding: 18px 12px; } } </style> <style> .ui-datepicker select.ui-datepicker-month, .ui-datepicker select.ui-datepicker-year { width: 48%; margin-top: 0; margin-bottom: 0; line-height: 25px; text-indent: 3px; color: #888; border-color: #DDD; background-color: #FDFDFD; -webkit-appearance: none; /*Optionally disable dropdown arrow*/ } </style> <!-- jQuery --> <script src="/js/jquery.min.js"></script> <script src="/js/jquery-ui.min.js"></script> <!-- Theme Javascript --> <script src="/js/utility.js"></script> <script src="/js/demo/demo.js"></script> <script src="/js/main.js"></script> <script src="/js/pages.js"></script> <!-- END: PAGE SCRIPTS --> </body> </html>
package com.damu.servlet; import com.damu.dao.UsersDAO; import com.damu.entity.Users; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet("/updategrades") public class GradeUpdateServlet extends HttpServlet{ private UsersDAO usersDAO=new UsersDAO(); @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { this.doPost(req,resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //获取用户要更新的数据 String name=req.getParameter("name"); String grade=req.getParameter("grade"); String chengji=req.getParameter("chengji"); System.out.println(name+grade+chengji); //创建用户对象 Users user=new Users(name,grade,Integer.parseInt(chengji)); System.out.println(user.getName()+user.getCourseid()+user.getChengji()); //提交更新 usersDAO.updateGrade(user); System.out.println(user.getName()+user.getCourseid()+user.getGrade()); resp.sendRedirect("/Gradedetail?courseid="+user.getCourseid()); } }
package com.damu.dao; import com.damu.entity.Users; import com.damu.utils.SqlSessionFactoryUtils; import org.apache.ibatis.session.SqlSession; import java.util.List; public class UsersDAO { private SqlSession sqlSession; private List<Users> list; private Users user; private SqlSession getSession() { sqlSession = SqlSessionFactoryUtils.getSqlSessionFactory().openSession(); return sqlSession; } /** * 查询全部用户 * @return */ public List<Users> findAll() { try { list = getSession().selectList("findUsers"); } catch (Exception e) { e.printStackTrace(); } return list; } /** * 查询单个用户根据编号 * @return */ public Users findById(Integer id) { try { user = getSession().selectOne("findUsers",new Users(id)); } catch (Exception e) { e.printStackTrace(); } finally { sqlSession.close(); } return user; } /** * 增加一个新用户到数据库的方法 * @return */ public Users addUser(Users user) { try { System.out.println("user==="+user); //返回值:是insert执行过程中影响的行数 getSession().insert("addUser",user); sqlSession.commit(); } catch (Exception e) { e.printStackTrace(); } finally { sqlSession.close(); } return user; } /** * 查询全部用户的成绩 * @return */ public List<Users> findGrade() { try { list = getSession().selectList("findGrade"); } catch (Exception e) { e.printStackTrace(); } finally { sqlSession.close(); } return list; } /** * 查询单个用户根据成绩 * @return */ public Users GradefindById(String courseid) { try { user = getSession().selectOne("findGrade",new Users(courseid)); } catch (Exception e) { e.printStackTrace(); } finally { sqlSession.close(); } return user; } /** * 修改成绩的方法 * @return */ public Users updateGrade(Users user) { try { System.out.println("user==="+user); //返回值:是insert执行过程中影响的行数 getSession().update("updateGrade",user); sqlSession.commit(); } catch (Exception e) { e.printStackTrace(); } finally { sqlSession.close(); } return user; } /** * 用于修改用户资料的方法 * @return */ public Users updateUsers(Users user) { try { System.out.println("user==="+user); //返回值:是insert执行过程中影响的行数 getSession().update("updateUser",user); sqlSession.commit(); } catch (Exception e) { e.printStackTrace(); } finally { sqlSession.close(); } return user; } /** * 用于删除用户资料的方法 * @return */ public void delUsers(Integer id) { try { getSession().delete("delUsers",id); //返回值:是insert执行过程中影响的行数 sqlSession.commit(); } catch (Exception e) { e.printStackTrace(); } finally { sqlSession.close(); } } }
package com.damu.entity; import java.util.Date; public class Users { private String name; private String grade; private String coursename; private Integer uid; private String courseid; private Integer chengji; private Integer age;//用户年龄 private String gender;//用户性别 private String phone;//用户电话联系 private String email;//用户邮箱 private String adress; private Date createTime;//账号创建时间 private Date updateTime;//账号最后修改时间 private Date lastLogin;//用户最后登录时间 private Integer userState;//用户账号状态 private String remark; private Integer id;//用户编号 private String username;//登陆账号 public Users(Integer age, String gender, String phone, String email, String adress, Date updateTime, String remark, Integer id) { this.age = age; this.gender = gender; this.phone = phone; this.email = email; this.adress = adress; this.updateTime = updateTime; this.remark = remark; this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Users(String courseid) { this.courseid = courseid; } public Users(Integer id) { this.id = id; } public Users() { } public Users(Integer age, String gender, String phone, String email, String adress, Date createTime, Date updateTime, Date lastLogin, String username, String userpass,Integer userState) { this.age = age; this.gender = gender; this.phone = phone; this.email = email; this.adress = adress; this.createTime = createTime; this.updateTime = updateTime; this.lastLogin = lastLogin; this.username = username; this.userpass = userpass; this.userState=userState; } public Users(String username, String userpass, Integer age, String gender, String phone, String email, String adress, Date createTime, Date updateTime, Date lastLogin) { this.username = username; this.userpass = userpass; this.age = age; this.gender = gender; this.phone = phone; this.email = email; this.adress = adress; this.createTime = createTime; this.updateTime = updateTime; this.lastLogin = lastLogin; } private String userpass;//登陆密码 public String getUserpass() { return userpass; } public void setUserpass(String userpass) { this.userpass = userpass; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getAdress() { return adress; } public void setAdress(String adress) { this.adress = adress; } public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { this.createTime = createTime; } public Date getUpdateTime() { return updateTime; } public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } public Date getLastLogin() { return lastLogin; } public void setLastLogin(Date lastLogin) { this.lastLogin = lastLogin; } public Integer getUserState() { return userState; } public void setUserState(Integer userState) { this.userState = userState; } public String getRemark() { return remark; } public void setRemark(String remark) { this.remark = remark; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getCourseid() { return courseid; } public void setCourseid(String courseid) { this.courseid = courseid; } public Integer getChengji() { return chengji; } public void setChengji(Integer chengji) { this.chengji = chengji; } public Integer getUid() { return uid; } public void setUid(Integer uid) { this.uid = uid; } public String getGrade() { return grade; } public void setGrade(String grade) { this.grade = grade; } public String getCoursename() { return coursename; } public void setCoursename(String coursename) { this.coursename = coursename; } public Users(String grade, String coursename, String courseid) { this.grade = grade; this.coursename = coursename; this.courseid = courseid; } public Users(String name,String grade,Integer chengji) { this.grade = grade; this.chengji = chengji; this.name = name; } }
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> <html> <head> <meta charset="utf-8"> <title>欢迎来到苏州科技大学教师后台管理系统</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="/css/theme.css"> <link rel="stylesheet" type="text/css" href="/css/admin-forms.css"> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script> <![endif]--> </head> <body class="admin-validation-page" data-spy="scroll" data-target="#nav-spy" data-offset="200"> <div id="main"> <header class="navbar navbar-fixed-top navbar-shadow"> <div class="navbar-branding"> <a class="navbar-brand" href="/index.html"> <H3>苏州科技大学后台管理系统</H3> </a> <span id="toggle_sidemenu_l" class="ad ad-lines"></span> </div> </header> <aside id="sidebar_left" class="nano nano-light affix"> <div class="sidebar-left-content nano-content"> <header class="sidebar-header"> <div class="sidebar-widget author-widget"> <div class="media"> <a class="media-left" href="#"> <img src="/images/head.jpg" class="img-responsive"> </a> <div class="media-body"> <div class="media-author">杜景龙</div> <div class="media-links"> <a href="login.html">退出</a> </div> </div> </div> </div> <div class="sidebar-widget search-widget hidden"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-search"></i> </span> <input type="text" id="sidebar-search" class="form-control" placeholder="Search..."> </div> </div> </header> <ul class="nav sidebar-menu"> <li class="sidebar-label pt20">学生信息</li> <li class="active"> <a href="cake_list.html"> <span class="glyphicon glyphicon-book"></span> <span class="sidebar-title">现有学生</span> </a> </li> <li> <a href="${pageContext.request.contextPath}/addusers.jsp"> <span class="glyphicon glyphicon-home"></span> <span class="sidebar-title" >添加学生</span> </a> </li> <li class="sidebar-label pt20">课程管理</li> <li class="active"> <a href="catalog_list.html"> <span class="glyphicon glyphicon-book"></span> <span class="sidebar-title">学生成绩</span> </a> </li> <li> <a href="catalog_add.html"> <span class="glyphicon glyphicon-home"></span> <span class="sidebar-title">添加课程</span> </a> </li> </ul> <div class="sidebar-toggle-mini"> <a href="login.html"> <span class="fa fa-sign-out"></span> </a> </div> </div> </aside> <section id="content_wrapper"> <section id="content" class="table-layout animated fadeIn"> <div class="tray tray-center"> <div class="content-header"> <h2> 学生管理</h2> <p class="lead"></p> </div> <c:set var="user" value="${user}"></c:set> <div class="row"> <div class="col-md-8 col-md-offset-2"> <form class="form-horizontal" action="${pageContext.request.contextPath}/updategrades"> <input type="hidden" name="uid" value="${user.courseid}"> <div class="form-group"> <label class="col-sm-2 control-label">用户账号</label> <div class="col-sm-10"> <p class="form-control-static">${user.name}</p> </div> </div> <div class="form-group"> <label for="chengji" class="col-sm-2 control-label">成绩</label> <div class="col-sm-10"> <input type="text" class="form-control" id="chengji" value="${user.chengji}" name="chengji" placeholder="请输入成绩"> </div> </div> <div class="form-group"> <input type="submit" value="提交数据更新" class="btn btn-primary"> </div> </form> </div> </div> </div> </section> </section> </div> <style> /* demo page styles */ body { min-height: 2300px; } .content-header b, .admin-form .panel.heading-border:before, .admin-form .panel .heading-border:before { transition: all 0.7s ease; } /* responsive demo styles */ @media (max-width: 800px) { .admin-form .panel-body { padding: 18px 12px; } } </style> <style> .ui-datepicker select.ui-datepicker-month, .ui-datepicker select.ui-datepicker-year { width: 48%; margin-top: 0; margin-bottom: 0; line-height: 25px; text-indent: 3px; color: #888; border-color: #DDD; background-color: #FDFDFD; -webkit-appearance: none; /*Optionally disable dropdown arrow*/ } </style> <!-- jQuery --> <script src="/js/jquery.min.js"></script> <script src="/js/jquery-ui.min.js"></script> <!-- Theme Javascript --> <script src="/js/utility.js"></script> <script src="/js/demo/demo.js"></script> <script src="/js/main.js"></script> <script src="/js/pages.js"></script> <!-- END: PAGE SCRIPTS --> </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.damu.entity.Users"> <!--<select id="findUsers" resultType="com.damu.entity.Users">--> <select id="findUsers" resultMap="forUsers"> select * from users <if test="id != null"> where id = #{id} </if> </select> <resultMap id="forUsers" type="com.damu.entity.Users"> </resultMap> <select id="findGrade" resultMap="forGrade"> select * from chengji <if test="courseid != null"> where courseid = #{courseid} </if> </select> <resultMap id="forGrade" type="com.damu.entity.Users"> </resultMap> <update id="updateGrade"> UPDATE chengji <set> <if test="name!=null">name = #{name},</if> <if test="grade!=null">grade =#{grade},</if> <if test="chengji!=null">chengji =#{chengji},</if> </set> where courseid=#{courseid} </update> <insert id="addUser" useGeneratedKeys="true" keyProperty="id"> insert into users(username,userpass,age,gender,phone,email,adress,createTime,updateTime,lastLogin,userState,remark) value(#{username},#{userpass},#{age},#{gender},#{phone},#{email},#{adress},#{createTime},#{updateTime},#{lastLogin},#{userState},#{remark}) </insert> <update id="updateUser"> UPDATE users <set> <if test="username!=null">username = #{username},</if> <if test="userpass!=null">userpass = #{userpass},</if> <if test="age!=null">age =#{age},</if> <if test="gender!=null">gender =#{gender},</if> <if test="phone!=null">phone =#{phone},</if> <if test="email!=null">email =#{email},</if> <if test="adress!=null">adress =#{adress},</if> <if test="createTime!=null">createTime =#{createTime},</if> <if test="updateTime!=null">updateTime =#{updateTime},</if> <if test="lastLogin!=null">lastLogin =#{lastLogin},</if> <if test="userState!=null">userState =#{userState},</if> <if test="remark!=null">remark =#{remark},</if> </set> where id=#{id} </update> <delete id="delUsers"> delete from users where id=#{id} </delete> </mapper>
0
收起
正在回答 回答被采纳积分+1
3回答
Java数据库开发与实战应用2018版
- 参与学习 人
- 提交作业 277 份
- 解答问题 4297 个
Java数据库开发的必备技能,从流行的MySQL数据库开始,到Java原生的数据库管理接口JDBC的使用,再到常用的数据持久化框架MyBatis,让你向Java工程师的目标又迈进了一步!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星