响应用户操作
关于介绍Spring简化用户响应操作
用thymeleaf代替JSP。
thymeleaf提供了更加简洁的动态页面创建方式。
使写出来的页面“像”一个静态页面。
在pom.xml中增加thymeleaf软件包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
在resources 目录下创建templates子目录
在templates下创建hello.html
**【实现前后端开发人员 的分离】
页面跳转
JSP中 可以使用请求转发【request.getRequestDispatcher(rul).forward(request,response)))】
或者重定向【response.sendRedirect()】
现在直接用户请求
localhost:8080/hello… 系统跳转到hello.html
Action
@RequestMapping("hello2")
public String hello2() {
return "hello";
}
函数返回值为 String ,返回值为跳转的页面名。
直接输入
localhost:8080/hello2
【IDEA环境下函数前面会出现“叶片图标”】
点击该图标,会进入相应 的html界面【方便开发人员】
thymeleaf简单实用。实现