发表于: 2017-04-16 23:53:40

2 1339


今天完成的事:

敲完了增删改查功能的代码(代码中method没写全,没做异常处理)

@Controller
public class StudentController {
Logger log=Logger.getLogger(StudentController.class);
   @Resource
   private StudentService studentService;

   @RequestMapping("/regist")
public String regist(Model model){
log.info("regist方法被调用!");
       Student student=new Student();
       model.addAttribute("student",student);
       return "regist";
   }
@RequestMapping(value="/register",method = RequestMethod.POST)
public String register(
@ModelAttribute Student student,
           Model model){
log.info("register方法被调用==参数student"+student);
       long timeNow=System.currentTimeMillis();
       student.setCreate_at(timeNow);
       studentService.addStudent(student);
       return "redirect:/login";
   }
@RequestMapping("/login")
public String login(){
return "login";
   }

@RequestMapping("/loginer")
public String login(@RequestParam String name,@RequestParam String password){
log.info("login方法被调用!name="+name+",password="+password);
           if(studentService.getByNameAndPwd(name,password)!=null){
return "redirect:/showList";
           }else {
return "login";
           }
}
@RequestMapping("/showList")
public String showList(Model model){
log.info("showList方法被调用");
       List<Student> studentList= new ArrayList<Student>();
       studentList=studentService.getAllStudent();
       model.addAttribute("studentList",studentList);
       return "showlist";
   }
@RequestMapping("/delete/{id}")
public String delete(@PathVariable("id") int id){
log.info("delete方法被调用 id="+id);
       studentService.deleteStudent(id);
       return "redirect:/showList";
   }
@RequestMapping("/update")
public String update(Student student,Model model){
log.info("update方法被调用 id="+student);
       model.addAttribute("student",student);
       return "update";
   }@RequestMapping("updateNow")
public String updateNow(@ModelAttribute Student student){
log.info("updateNow方法被调用。student"+student);
       long timeNow=System.currentTimeMillis();
       student.setUpdate_at(timeNow);
       studentService.updateStudent(student);
       return "redirect:showList";
   }
}

问题:

我的更新按钮是放在学生详细列表后面的,下面是该jsp文件代码,执行更新的SQL语句是包含所有字段的属性的。点击更新后有两个参数需要传到控制器(控制器再调度填写内容的页面)一个是ID,一个是不给用户修改的create-at时间。因为意识到面临实际情况时可能不止有两个参数需要传递到控制器中,所以此处决定传递Student类,遇到的问题是我以${Student}方式传递类时,控制器不能正确获得该内容(感觉jsp语法有问题,但本身对其不熟所以还没解决)

<body>
<h2>详细信息列表</h2>
<form>
   <table>
       <tr>
           <td>ID</td>
           <td>名字</td>
           <td>密码</td>
           <td>抵达时间</td>
           <td>QQ</td>
           <td>修真类型</td>
           <td>线上学号</td>
           <td>日报链接</td>
           <td>毕业院校</td>
           <td>立愿</td>
           <td>审核师兄</td>
           <td>引荐师兄</td>
           <td>创建日期</td>
           <td>更新日期</td>
           <td>删除</td>
           <td>更新</td>
       </tr>
       <c:forEach items="${studentList}" var="student">
       <tr>
               <td>${student.id}</td>
               <td>${student.name}</td>
               <td>${student.password}</td>
               <td>${student.arrival_time}</td>
               <td>${student.qq}</td>
               <td>${student.study_type}</td>
               <td>${student.number_online}</td>
               <td>${student.diary_link}</td>
               <td>${student.school}</td>
               <td>${student.vow}</td>
               <td>${student.assessor}</td>
               <td>${student.referee}</td>
               <td>${student.create_at}</td>
               <td>${student.update_at}</td>
               <td><a href="/delete/${student.id}">删除</a> </td>
               <%--<td><a href="/update/${student}" >更新</a> </td>--%>
               <td>
                   <form:form action="/update" >
                       <input type="hidden" about="" value="${student}"/>
                       <input type="submit" value="更新" />
                   </form:form>
               </td>
       </tr>
       </c:forEach>
</table>
</form>
</body>

明天计划的事:将项目部署到服务器

总结:好好学习!


返回列表 返回列表
评论

    分享到