contrllor //修改 int up(Student student); // 删除 int del(Integer id); // 增加 int add(Student student);
seveceoimpl
@Override public int add(Student student) { int add = studentMapper.add(student); return add; } @Override public int del(Integer id)
{ // System.out.println("service:"+studentMapper.del(id)); return studentMapper.del(id); }
@Override public int up(Student student) { int up = studentMapper.up(student); return up; }
mapper
<!--修改--> <update id="up"> update lzj_tb_Student set name=#{name}, sex=#{sex}, age=#{age} where no=#{no} </update> <!-- 删除--> <delete id="del" > delete from lzj_tb_Student where id =#{id} </delete> <!--增加--> <insert id="add"> <!-- insert into lzj_tb_Student(name,age) values (#{name},#{age}) where id =#{id}--> insert into lzj_tb_Student(id,name,stuname,age,sex,tel,address,clazz,delflg,mno) values(#{id},#{name},#{stuname},#{age},#{sex},#{tel},#{address},#{clazz},#{delflg},#{mno}) <!-- insert into lzj_tb_Student value(#{no},#{id},#{name},#{stuname},#{age},#{sex},#{tel},#{address},#{clazz},#{delflg},#{mno})--> </insert>
前台
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <!-- <th:block th:include="include::title('学生展示')"/>--> </head> <body> <!-- <th:block th:include="top"/>--> <table border="1" align="center"> <thead> <tr> <th>学号</th> <th>账号</th> <th>姓名</th> <th>考试号</th> <th>年龄</th> <th>性别</th> <th>电话</th> <th>地址</th> <th>班级</th> <th>标记</th> <th>专业</th> <th>操作</th> <th><a th:href="|/thy/adde|">增加</a></th> <!-- table->tr->th*2 --> <!-- tr>td*3--> </tr> </thead> <tbody> <!-- 循环:th:each。就是 Java 中的增强 for List<Student> list; for(Student student : list){ } --> <tr th:each="stu:${list}"> <td th:text="${stu.no}"></td> <td th:text="${stu.id}"></td> <td th:text="${stu.name}"></td> <td th:text="${stu.stuname}"></td> <td th:text="${stu.age}"></td> <td th:text="${stu.sex == '1' ? '男':'女'}"></td> <td th:text="${stu.tel}"></td> <td th:text="${stu.address}"></td> <td th:text="${stu.clazz}"></td> <td> <span th:if="${stu.delflg == '1'}">可用</span> <span th:if="${stu.delflg != '1'}">禁用</span> </td> <td th:text="${stu.mno}"></td> <!-- <td>--> <!-- <img th:src="${stu.file}" width="100"/>--> <!-- </td>--> <!-- <td th:text="${stu.version}"></td>--> <!-- <td th:text="${stu.createTime}"></td>--> <td> <a th:href="|/thy/edit?no=${stu.no}|">修改</a> <a th:href="|/thy/del?id=${stu.id}|">删除</a> <!-- <button type="button" th:οnclick="|edit('${stu.no}')|">修改</button>--> <!-- <button type="button" th:οnclick="|del(${stu.no})|">删除</button>--> <!-- <button type="button" th:οnclick="edit([[${stu.no}]])">修改</button>--> <!-- <button type="button" th:οnclick="del([[${stu.no}]])">删除</button>--> </td> </tr> </tbody> </table> <!-- <th:block th:include="footer"/>--> </body> </html>
修改
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <!-- <th:block th:include="include::title('学生修改')"/>--> <title>1234134234234</title> </head> <body> <!--<th:block th:include="top"/>--> <!--<div id="d1" th:insert="top"></div>--> <!--<div id="d2" th:replace="top"></div>--> <!--<hr>--> <!--<th:block th:include="include::top"/>--> <!--<th:block th:include="include::footer"/>--> <form action ="/thy/up"> <table th:object="${stu}"> <tr> <td>学号:</td> <td><input type="text" th:field="*{no}"/></td> </tr> <tr> <td>姓名:</td> <td><input type="text" th:field="*{name}"/></td> </tr> <tr> <td>性别:</td> <td> <label><input type="radio" name="sex" value="1" th:field="*{sex}"/>男</label> <label><input type="radio" name="sex" value="0" th:field="*{sex}"/>女</label> </td> </tr> <tr> <td>专业</td> <td> <select th:field="*{mno}" name="mno"> <option value="">请选择专业</option> <option value="M10001">软件工程</option> <option value="M10002">土木工程</option> <option value="M10003">信息工程</option> <option value="M10004">电竞专业</option> <option value="M10005">美术</option> <option value="M10006">体育</option> <option value="M10006">java</option> </select> </td> </tr> </table> <input type="submit" value="提交"> <input type="reset" value="重置"> </form> </body> </html>
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <!-- <th:block th:include="include::title('学生修改')"/>--> <title>1234134234234</title> </head> <body> <!--<th:block th:include="top"/>--> <!--<div id="d1" th:insert="top"></div>--> <!--<div id="d2" th:replace="top"></div>--> <!--<hr>--> <!--<th:block th:include="include::top"/>--> <!--<th:block th:include="include::footer"/>--> <form action ="/thy/add" > <!-- action="<%=basePath%>annotation/paramPost" method="post"--> <!--<table th:object="${stu}">--> <table> <tr> <td>id:</td> <td><input type="text" name="id" placeholder="请输入学号"/></td> </tr> <tr> <td>姓名:</td> <td><input type="text" name="name" /></td> </tr> <tr> <td>性别:</td> <td valign="middle" align="left"> <!--<input type="text" class="inputgri" name="sex" th:value="${user.sex}"/>--> <label class="radio-inline"> <input type="radio" name="sex" id="1" value="1" checked> 男 </label> <label class="radio-inline"> <input type="radio" name="sex" id="0" value="0"> 女 </label> </td> <!-- <label><input type="radio" name="sex" value="1" th:field="*{sex}"/>男</label>--> <!-- <label><input type="radio" name="sex" value="0" th:field="*{sex}"/>女</label>--> </tr> <tr> <td>专业</td> <td> <select name="mno"> <option value="">请选择专业</option> <option value="M10001">软件工程</option> <option value="M10002">土木工程</option> <option value="M10003">信息工程</option> <option value="M10004">电竞专业</option> <option value="M10005">美术</option> <option value="M10006">体育</option> <option value="M10006">java</option> </select> </td> </tr> </table> <input type="submit" value="提交"> <input type="reset" value="重置"> <!-- <button style="color: yellowgreen" οnclick="paramPost()">点我发送add请求</button>--> </form> </body> <!-- <script type="text/javascript"> //post请求参数带在url中。 function paramPost() { $.ajax({ type:"post", //参数在url中,载荷是查询字符串,就是没有请求体 // url:"paramPost?name=jack&age=25", url:"thy/add", //参数在请求体中,js对象和json对象都可以提交,默认是提交表单数据 data:student, dataType:"json", success: function(data){ console.log(data); alert(data); alert(data.sss); } }); } </script>--> </html>