发表于: 2018-01-11 23:23:41
2 634
1、讲了小课堂,翻车了
2、任务二进行中,明白了controller中页面跳转的思路。
(1)在comtroller中调用service层的方法获取数据库的数据,并且将其通过modelandview的addObject方法放置到域中
(2)在jsp页面中通过jsp标签进行读取
@RequestMapping(value = "/student/new", method = RequestMethod.POST)
public String news(StudentGet sg) {
student = ChangeUtil.studentChange(sg);
//student.setCreate_at(System.currentTimeMillis());交给service
servicelmpl.insertStudent(student);
return "redirect:/student/index";
}
通过响应请求student/new,利用changeutil类中的方法改变对应字段的数据放在参数student中,再利用service层加入数据,把字段重新返回到index页面上。
1、完成上传小课堂的后续
2、通过controller在jsp页面上显示数据库内容
1、纠结于jsp页面跳转没有指定存在的jsp文件夹和后缀名,答案在配置文件中。
<form method="get" action="${pageContext.request.contextPath}/student/index?">
@RequestMapping(value = "/student/list", method = RequestMethod.GET)
<!-- 配置sprigmvc视图解析器:解析逻辑试图
后台返回逻辑试图:index
视图解析器解析出真正物理视图:前缀+逻辑试图+后缀====/WEB-INF/jsps/list.jsp
-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!--前缀-->
<property name="prefix" value="/jsps/"/>
<!--后缀-->
<property name="suffix" value=".jsp"/>
</bean>
2、输出调用的方法,不知道加to.string(),导致问题找不到。
public void selectStudentById() throws Exception {
System.out.println("aa"+service.selectStudentById(1).toString());
}
3、在测试类中加入@ContextConfiguration,调用多个配置文件,容易忘记
(locations = {"classpath*:spring-ctx-application.xml", "classpath*:spring-ctx-consumer.xml" })
四、收获
1、小课堂讲的太快,照着准备好的ppt内容讲,思路没有弄清,小课堂讲课水平需要练练。
2、<dependency>
</dependency>
评论