发表于: 2018-02-28 23:56:25

1 619


今天把StudentController里面用restful修改了一下

@Controller
//@RequestMapping("")
public class StudentController {
@Autowired
   StudentService studentService;

   @RequestMapping("listStudent")
public ModelAndView listStudent(Page page){

ModelAndView mav = new ModelAndView();
       List<Student> ss= studentService.list(page);
       int total = studentService.total();

       page.caculateLast(total);

       // 放入转发参数
       mav.addObject("ss", ss);
       // 放入jsp路径
       mav.setViewName("listStudent");
       return mav;
   }

@RequestMapping(value = "/addStudent",method = RequestMethod.POST)
public ModelAndView addStudent(Student student){
studentService.add(student);
       ModelAndView mav = new ModelAndView("redirect:/listStudent");
       return mav;
   }
@RequestMapping(value = "/deleteStudent",method = RequestMethod.DELETE)
public ModelAndView deleteStudent(Student student){
studentService.delete(student);
       ModelAndView mav = new ModelAndView("redirect:/listStudent");
       return mav;
   }
@RequestMapping(value = "editStudent/{id}",method = RequestMethod.GET)
public ModelAndView editStudent(Student student){
Student s= studentService.get(student.getId());
       ModelAndView mav = new ModelAndView("editStudent");
       mav.addObject("s", s);
       return mav;
   }
@RequestMapping(value = "updateStudent/{id}",method = RequestMethod.PUT)
public ModelAndView updateStudent(Student student){
studentService.update(student);
       ModelAndView mav = new ModelAndView("redirect:/listStudent");
       return mav;
   }

问题出现了,改了之后,点击删除增加什么的,不能继续跳转了

listStudent里面的内容是:

<%@ page language="java" contentType="text/html; charset=UTF-8"
   pageEncoding="UTF-8" import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<div style="width:500px;margin:0px auto;text-align:center">
  <table align='center' border='1' cellspacing='0'>
      <tr>
          <td>id</td>
          <td>name</td>
        <td>qq</td>
        <td>major</td>
          <td>编辑</td>
          <td>删除</td>
      </tr>
      <c:forEach items="${ss}" var="s" varStatus="st">
<tr>
              <td>${s.id}</td>
              <td>${s.name}</td>
           <td>${s.qq}</td>
           <td>${s.major}</td>
              <td><a href="/editStudent/${s.id}">编辑</a></td>
              <td><a href="/deleteStudent/${s.id}">删除</a></td>
          </tr>
      </c:forEach>
</table>
  <div style="text-align:center">
     <a href="?start=0">首  页</a>
     <a href="?start=${page.start-page.count}">上一页</a>
     <a href="?start=${page.start+page.count}">下一页</a>
     <a href="?start=${page.last}">末  页</a>
  </div>
   <div style="text-align:center;margin-top:40px">
      <form method="post" action="addStudent/">
        分类名称: <input name="name" value="" type="text"> <br><br>
        <input name="qq" value="" type="text"> <br><br>
        <input name="major" value="" type="text"> <br><br>
        <input type="submit" value="增加分类">
     </form>
   </div>
</div>

editStudent里面的内容是:

<%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<div style="width:500px;margin:0px auto;text-align:center">
   <div style="text-align:center;margin-top:40px">
       <form method="post" action="updateStudent/{id}">
           <input type="hidden" name="method" value="PUT">
           分类名称: <input name="name" value="${s.name}" type="text"> <br><br>
           <input name="qq" value="${s.qq}" type="text"> <br><br>
           <input name="major" value="${s.major}" type="text"> <br><br>
           <input type="hidden" value="${s.id}" name="id">
           <input type="submit" value="增加分类">
       </form>
   </div>
</div>

别的都没改动过,昨天是可以照常运行的,修改的地方,除了Controller里面的POST,GET,DELETE,PUT外,只有

  <td><a href="/editStudent/${s.id}">编辑</a></td>

              <td><a href="/deleteStudent/${s.id}">删除</a></td>

<form method="post" action="addStudent/">
<form method="post" action="updateStudent/{id}">

雷雷帮我加了一行:

<input type="hidden" name="method" value="PUT">

反复调试过,就是不行啊。

点击删除的报错是这个:

二。在chrome浏览器里安装了postman,,准备测试接口,结果接口今天出问题鸟


明天的计划:提交任务二,

遇到的问题:嗯,我的项目无法运行了

今天的收获:复习了restful,安装了postman

java任务二开始时间:2018.01.25

预计demo时间:2018.02.12

可能有延期风险,原因是:基础比较差,

禅道链接地址:http://task.ptteng.com/zentao/project-task-501.html



返回列表 返回列表
评论

    分享到