发表于: 2017-10-15 22:11:30
1 631
今天完成的事情
尝试用ssm框架,对之前建立的报名表进行操作,并显示到页面上。
先尝试只对id和name进行操作
项目结构:
在controller中进行逻辑操作:
@Controller
@RequestMapping("")
public class StudentController {
@Autowired
StudentService studentService;
@RequestMapping("listStudent")
public ModelAndView listStudent(Page page){
ModelAndView mav=new ModelAndView();
PageHelper.offsetPage(page.getStart(),5);
List<Student> cs=studentService.list();
int total=(int)new PageInfo(cs).getTotal()
page.caculateLast(total);
mav.addObject("cs",cs);
mav.setViewName("listStudent");
return mav;
}
@RequestMapping("addStudent")
public ModelAndView addStudent(Student student){
studentService.add(student);
ModelAndView mav=new ModelAndView(
"redirect:/listStudent");
return mav;
}
@RequestMapping("deleteStudent")
public ModelAndView deleteStudent(Student student){
studentService.delete(student);
ModelAndView mav=new ModelAndView(
"redirect:/listStudent");
return mav;
}
@RequestMapping("editStudent")
public ModelAndView editStudent(Student student){
Student c=studentService.get(student.getID());
ModelAndView mav=new ModelAndView(
"editStudent");
mav.addObject("c",c);
return mav;
}
@RequestMapping("updateStudent")
public ModelAndView updateStudent(Student student){
studentService.update(student);
ModelAndView mav=new ModelAndView(
"redirect:/listStudent");
return mav;
}
}
对于分页操作,使用了分页插件pagehelper,只需要在controller中的listStudent中添加如上语句,再写一个page类即可:
public class Page {
int start=0;
int count=5;
int last=0;
public int getStart(){
return start;}
public void setStart(int start) {
if(start<0)start=0;
this.start = start;}
public int getCount() {
return count;}
public void setCount(int count) {
this.count = count;}
public int getLast(){
return last;
}
public void setLast(int last){
this.last=last;
}
public void caculateLast(int total){
if(0==total%count)
last=total-count;
else
last=total-total%count;
}
}
执行结果如下:
明天的计划
学习jetty
遇到的问题
输入字符,点击增加记录后,可以增加,显示为空,如上的18,19所示,还不清楚原因。
收获
对于ssm整合框架有了大概的了解
评论