SpringBoot's default page mapping path (that is, the location where template files are stored) is "classpath:/templates/*.html". The static file path is "classpath:/static/", which can store static files shared by JS, CSS and other templates
Store the HTML page in the resources/static directory Access
Put the html file in the resources/static directory and access it directly through the ip port number file path
文件放在resources/static/view目录下
文件放在resources/static目录下
The resources in the templates directory under the SpringBoot project are protected by default and do not have open access permissions. This is because the templates
folder is where template files are placed, so a view parser is needed to parse it. Therefore, it must be accessed through the inside of the server, which means going through the process of controller→ service→ view resolver. At the same time, there are security issues. For example, if you put your background
html files in templates, and this folder is open to the outside world, there will be security risks.
Method: Open access permissions in application.yml or application.properties configuration file
spring: resources: static-locations: classpath:/META-INF/resources/, classpath:/resources/, classpath:/static/, classpath:/public/, classpath:/templates/
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/templates/After the configuration is completed, start SpringBoot , you can directly access the static resources in the templates directory by entering the address in the browser.
<!-- thymeleaf依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
@Controller public class testController { @RequestMapping("/test") public String test() { return "/login1"; } }Access through interface
The above is the detailed content of What is the process for java SpringBoot to access HTML?. For more information, please follow other related articles on the PHP Chinese website!