发表于: 2018-03-25 23:28:49

1 398


今天完成的事情:

1.SSM的RESTful的controller,新增时先跳转到student.jsp页面获取对象,之后使用对象完成新增操作。

@Controller
@RequestMapping("/haha")
public class StudentController3 {
@Autowired
   private StudentService studentService;
//通过id查找
   @RequestMapping(value = "/student/{id}",method = RequestMethod.GET)
public String get(@PathVariable("id") Long id, Model model)throws Exception{
Student student=studentService.getStudentById(id);
model.addAttribute("student",student);
return "test";
}
//获取全部对象
   @RequestMapping(value = "/getAllStudents",method = RequestMethod.GET)
public String getAllStudents(Model model) throws Exception{
List<Student> studentsList=new ArrayList<>();
studentsList=studentService.getAllStudents();
model.addAttribute("studentList",studentsList);
return "list";
}
//删除
   @RequestMapping(value = "/delete/{id}",method = RequestMethod.GET)
public String deleteById(@PathVariable("id") Long id) throws Exception{
studentService.removeById(id);
return "success";
}
//新增
   @RequestMapping(value = "/add",method = RequestMethod.GET)
public String saveStudent()throws Exception{
return "student";
}
@RequestMapping(value = "/add",method = RequestMethod.POST)
public String saveStudent(Student student) throws Exception{
System.out.println(student);
studentService.addStudent(student);
return "redirect:/haha/getAllStudents";
}

项目结构。

sutdent.jsp

<body>
<form name="input" action="/haha/add" method="post">
姓名:<input type="text" name="name">
QQ:<input type="text" name="qq" >
职业:<input type="text" name="goal">
报道时间:<input type="text" name="registration_date">
毕业院校:<input type="text" name="graduated_from">
学号:<input type="text" name="number">
日报链接:<input type="text" name="daily_link">
立愿:<input type="text" name="pledge">
辅导师兄:<input type="text" name="senior">
从哪里了解到修真院:<input type="text" name="konw_form">
<input type="submit" value="提交">
</form>
</body>

明天的计划:

完成更新的TESTful接口。使用jetty,看下json。

遇到的问题:

通过问大家解决了,新增时前端和后端对象参数传递的问题。

收获:

完成SSM REST风格的查询,新增和删除。


返回列表 返回列表
评论

    分享到