发表于: 2018-02-03 23:40:35
2 823
今日完成:
1. 添加了增删改查四个jsp页面
2. 使用
<a href="/task2/itschool/menu">******进入目录******</a>
和
//目录
@RequestMapping(value = "/menu")
public String menu(){
//返回一个menu.jsp这个视图
return "menu";
}
进行页面跳转
3. 使用form提交表单,将数据传到后端
<form action="/task2/itschool/students/student" method="post">
<input name="id" type="number" placeholder="请输入查询ID">
<input type="submit" value="查找">
</form>
使用@RequestParam接收数据
@RequestMapping(value = "/students/student", method = RequestMethod.POST)
public ModelAndView getStudent(@RequestParam("id") int id){
Student student = studentService.selectStudent(id);
List<Student> students = new ArrayList<Student>();
students.add(student);
ModelAndView modelAndView = new ModelAndView("students");
modelAndView.addObject("students", students);
return modelAndView;
}
4. 通过@ModelAttribute可以接收一个实体类
RequestMapping(value = "/students", method = RequestMethod.POST)
public ModelAndView createStudent(@ModelAttribute("student") Student student){
studentService.insertStudent(student);
return this.listAllStudents();
}
5. 使用ModelAndView重定向页面,并且传输数据到jsp页面
ModelAndView modelAndView = new ModelAndView("students");
modelAndView.addObject("students", students);
return modelAndView;
6. Jsp页面使用<c:forEach </c:forEach>可以输出循环语句
<c:forEach items="${students}" var="student">
<tr>
<td>${student.id}</td>
<td>${student.name}</td>
<td>${student.QQ}</td>
<td>${student.type}</td>
<td>${student.stime}</td>
<td>${student.graschool}</td>
<td>${student.classnum}</td>
<td>${student.link}</td>
<td>${student.mentor}</td>
<td>${student.conbrother}</td>
<td>${student.hknow}</td>
<td><a href="/task2/itschool/students/information/${student.id}">更新</a></td>
<td><a href="/task2/itschool/students/${student.id}">删除</a></td>
</tr>
</c:forEach>
7. 使用ModelAndView传递数据可以在jsp页面通过${}获取
<a href="/task2/itschool/students/information/${student.id}">更新</a>
明日计划:
1. 给插入语句增加查重的效果,给查找语句添加没有信息的弹窗
2. 学习AJAX
3. 整理springmvc前后端交互的方法
4. 提交任务二
遇到的问题:
1. 对前后端数据传输的方式还很陌生,网上查到的有很多种方法,有传统的servlet,有使用AJAX,有springmvc自带的,有使用jquery,感觉特别乱
2. 使用json-taglib包在jsp页面上有什么优势,没发现使用json标签的作用
收获:
1. 将java后端与jsp页面结合,通过form表单,${},ModelAndView,@RequestParam,@ModelAttribute,
@PathVariable等进行数据传输
2. 熟悉基本的jsp页面,c:if标签的使用
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
评论