发表于: 2018-03-15 20:28:55
1 485
今日完成
1.完善了增删查改功能,増删改功能的实现;
@Controller
@RequestMapping("/user")
public class SpringController {
Student student;
@Autowired
StudentMapper studentMapper;
String message;
@RequestMapping(value = "listsall",method = RequestMethod.GET)
public ModelAndView listCategory(Page page) throws IOException {
ModelAndView mav = new ModelAndView();
List<Student> cs= studentMapper.findAll(page);
int total = studentMapper.total();
page.caculateLast(total);
// 放入转发参数
mav.addObject("listsall", cs);
// 放入jsp路径
mav.setViewName("listsall");
return mav;
}
@RequestMapping("/searchbyid")
public String jumptosearchid( ) throws IOException {
return "searchbyid";
}
/*
* 根据ID查询信息
* */
@RequestMapping(value = "/list",method = RequestMethod.GET)
public String select( Long ID, Model model) throws IOException {
student = studentMapper.findUserById(ID);
model.addAttribute("student", student);
return "list";
}
/*
* 根据姓名模糊查询*/
@RequestMapping("/searchbyname")
public String jumptosearcname( ) throws IOException {
return "searchbyname";
}
@RequestMapping(value = "/listbyname",method = RequestMethod.GET)
public String selectByName(String name, Model model) throws IOException {
List<Student> students2 = studentMapper.findUserByName(name);
model.addAttribute("lists",students2);
return "listbyname";
}
@RequestMapping(value = "/deletbyid/{ID}")
public String delect(@PathVariable("ID") int ID, Model model) throws Exception {
int a = studentMapper.deleteUser(ID);
if (a == 1) {
message = "数据删除成功";
} else {
message = "数据删除失败";
}
model.addAttribute("message", message);
return "deletbyid";
}
/*获取当前这条数据的信息*/
@RequestMapping(value = "/list/{ID}")
public String jumptoupdate(@PathVariable("ID") Long ID, Model model) throws IOException {
student = studentMapper.findUserById(ID);
System.out.println(student);
model.addAttribute("student", student);
return "update1";
}
@RequestMapping(value = "/updatecomplate")
public String update(Student student3,Model model) throws Exception {
int s=studentMapper.updateUser(student3);
System.out.println(student3);
if (s == 1) {
message = "数据修改成功";
}
else {
message = "数据修改失败";
}
model.addAttribute("message",message);
return "update2";
}
@RequestMapping("/new")
public String turntoinsert( ) throws IOException {
return "insert";
}
@RequestMapping(value = "/add")
public String insert(Student student2,Model model) throws Exception {
studentMapper.insertUser(student2);
Long a=student2.getID();
model.addAttribute("message2",a);
return "deletbyid";
}
}
2.加入分页查询功能;
只是简单实现了,还需更改.
明天计划
1.模糊查询加入分页查询,分页功能重写,加入分页插件;
2.修改/删除后点击按钮返回分页;
3.查找时Long类型转换为Date类型显示在页面,插入和更新时输入Date类型数据,转换为Long类型并存储;
4.AOP还没学习完,补上;
遇到问题
RESTful没来得及搞.
收获
表单form标签的用法.
评论