发表于: 2018-04-08 09:13:17
1 702
今天完成的事情:(一定要写非常细致的内容,比如说学会了盒子模型,了解了Margin)
完成了delete操作
之前出了点问题
我在listUser.jsp写如下代码
<td>
<form action="/delete/${user.id}" method="post"> //post
<input type="hidden" value="delete" name="_method"> //改行为改post为delete
<%--<input type="submit" value="删除">--%>
<button onClick="return fun()" >删除</button>
<script>
function fun(){
alert("删除成功")
}
</script>
</form>
该为 设置一个键跳转到
/delete/${user.id} // ${user.id}为取同行的id值
在controller层写以下代码
//删除
@RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
public ModelAndView delete(@PathVariable("id") Integer id) throws Exception{
userService.delete(id);
ModelAndView mav = new ModelAndView("redirect:/listUser");
return mav;
}
@PathVariable("id")为取上面{id}的值 赋予 id
ModelAndView mav = new ModelAndView("redirect:/listUser");
为跳转到/listUser
删除成功直接跳转到listUser
然后完成了add操作
<div style="text-align:center">
<a href="http://localhost:8080/addUser">添加用户</a>
</div>
首先在listUser.jsp添加以上代码
设置一个超链接到/addUser
@RequestMapping("/addUser")
public ModelAndView add(User user) throws Exception {
ModelAndView mav = new ModelAndView("addUser");
return mav;
}
在controller层添加以上代码 用来跳转到addUser.jsp
建立addUser.jsp
<%--
Created by IntelliJ IDEA.
User: luojiac
Date: 2018/4/5
Time: 下午9:16
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.util.*" isELIgnored="false"%>
<body style="background-image:url(/images/Alujpg.jpg);background-size: 1440px">
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<form action="/addUser/user" class="form-horizontal" role="form" method="post">
<div class="form-group">
<label for="stu_name" class="col-sm-2 control-label">stu_name</label>
<div class="col-sm-2">
<input type="text" class="form-control" name="stu_name" id="stu_name" value=""
placeholder="">
</div>
</div>
<div class="form-group">
<label for="profession" class="col-sm-2 control-label">profession</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="profession" name="profession" value=""
placeholder="">
</div>
</div>
<div class="form-group">
<label for="join_date" class="col-sm-2 control-label">join_date</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="join_date" name="join_date" value=""
placeholder="">
</div>
</div>
<div class="form-group">
<label for="online_id" class="col-sm-2 control-label">online_id</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="online_id" name="online_id" value=""
placeholder="">
</div>
</div>
<div class="form-group">
<label for="brother" class="col-sm-2 control-label">brother</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="brother" name="brother" value=""
placeholder="">
</div>
</div>
<div class="form-group">
<label for="school" class="col-sm-2 control-label">school</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="school" name="school" value=""
placeholder="">
</div>
</div>
<div class="form-group">
<label for="daily" class="col-sm-2 control-label">daily</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="daily" name="daily" value=""
placeholder="">
</div>
</div>
<div class="form-group">
<label for="wishing" class="col-sm-2 control-label">wishing</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="wishing" name="wishing" value=""
placeholder="">
</div>
</div>
<div class="form-group">
<label for="qq" class="col-sm-2 control-label">qq</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="qq" name="qq" value=""
placeholder="">
</div>
</div>
<div class="form-group">
<label for="heard" class="col-sm-2 control-label">heard</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="heard" name="heard" value=""
placeholder="">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">提交</button>
</div>
</div>
</form>
</body>
找了一个模版 来美化输入框
<form action="/addUser/user" class="form-horizontal" role="form" method="post">
<button type="submit" class="btn btn-default">提交</button>
主要的form 又submit 进入/addUser/user 方法为post
在controller层添加
@RequestMapping(value = "/addUser/user",method = RequestMethod.POST)
public ModelAndView addd(User user) throws Exception {
userService.add(user);
ModelAndView mav =new ModelAndView("redirect:/listUser");
//mav.setViewName("listUser");
return mav;
}
添加页面
添加成功了
然后做更改的时候遇到了些问题
明天计划的事情:(一定要写非常细致的内容)
做了更改
遇到的问题:(遇到什么困难,怎么解决的)
更改传入值的问题 如果传入id 无法在转页面的时候保存
传入user的话 需要改边框 或者更改参数 需要明天研究一下
收获:(通过今天的学习,学到了什么知识)
对ssm框架的运行更了解了
评论