【系统学习SpringBoot】初见Thymeleaf之SpringBoot访问项目中的 jsp/html
2017-08-05 21:24
791 查看
网上提供了许多方法
方法1
1 启动的类继承 extends SpringBootServletInitializer
2 重写configure方法
@Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder application) {
// TODO Auto-generated method stub
return application.sources(SampleSimpleApplication.class);
}
3 在resources下加入
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
这种方法,,我试了不行啊,,少了视图解析器的(ViewResolver),没有试图解析器。
浪费了一天发现下面的东西:
(1)pom.xml
其中这个依赖比较重要
(2).controller类
必须使用 @Controller,,测试过,使用@RestController不好使,,原因是@RestController组合注解中包含【@Responsebody:返回内容】
(3).目录结构,,spring Boot新建时会有一个 templates
因为SpringBoot集成了Thymeleaf,所以它会默认查找resources下面的templates这个目录下的文件。
大概就是这样,,
方法1
1 启动的类继承 extends SpringBootServletInitializer
2 重写configure方法
@Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder application) {
// TODO Auto-generated method stub
return application.sources(SampleSimpleApplication.class);
}
3 在resources下加入
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
这种方法,,我试了不行啊,,少了视图解析器的(ViewResolver),没有试图解析器。
浪费了一天发现下面的东西:
(1)pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>xatu.zsl</groupId> <artifactId>spring_boot_ajax</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>spring_boot_ajax</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <organization> <name>Pivotal Software, Inc.</name> <url>http://www.spring.io</url> </organization> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <!-- Compile --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <useSystemClassLoader>false</useSystemClassLoader> </configuration> </plugin> </plugins> </build> </project>
其中这个依赖比较重要
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
(2).controller类
必须使用 @Controller,,测试过,使用@RestController不好使,,原因是@RestController组合注解中包含【@Responsebody:返回内容】
(3).目录结构,,spring Boot新建时会有一个 templates
因为SpringBoot集成了Thymeleaf,所以它会默认查找resources下面的templates这个目录下的文件。
大概就是这样,,
相关文章推荐
- thymeleaf :springboot整合mybatis的web项目中使用html而不是jsp当页面渲染
- springboot学习(二)springboot项目整合前端,添加jsp的访问
- springboot如何使用thymeleaf模板访问html页面
- SpringBoot 同时整合thymeleaf html、vue html和jsp-在线助手
- SpringBoot项目如何访问jsp页面的示例代码
- springboot项目访问jsp文件
- Spring boot+ maven + thymeleaf + HTML 实现简单的web项目
- IntelliJ IDEA 学习SpringBoot(2) thymeleaf 资源访问和路径写法
- SpringBoot项目如何访问jsp页面
- 解决SpringBoot项目打成jar包访问不了jsp模板的问题: SpringBoot项目集成jsp模板打成war包 然后通过java -jar 命令启动访问
- springboot 在idea多模块下 子模块的web项目用内置tomcat启动访问jsp报404
- 【spring boot学习】:脚手架项目《婴儿商品管理系统》(一)
- springBoot 学习记录(四)- 访问jsp页面
- (3)Spring-boot学习 做一个简单的带访问数据库的web项目
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- springboot中整合activiti流程设计器时遇到访问项目需要输入tomcat用户名和密码的问题
- 深入学习spring-boot系列(三)--使用thymeleaf模板