spring中配置thymeleaf以及遇到的问题

1.在pom.xml文件中添加thymeleaf模板引擎

org.springframework.boot spring-boot-starter-thymeleaf

2.在application.properties中进行配置

#thymeleaf
#该路径根据自己项目进行指定
spring.thymeleaf.prefix=classpath:/templates/    
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
spring.thymeleaf.content-type=text/html
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML5

3.将相对应的html文件放到对应的文件夹中

在对应的文件夹中添加html文件

4.在controller中写入对应的跳转


@Controller
@RequestMapping("/login")
public class LoginController {

	@RequestMapping("/to_login")
	    public String to_login(){
	        return "login";
	    }
}

5.遇到的问题

在这里插入图片描述
如果出现上述问题记得检查自己的代码,本人就是因为在第一步中忘记添加依赖导致花费了半个小时找问题。
还有一点就是记得做好文件的管理:
在这里插入图片描述
在这里插入图片描述
需要将主控制文件放在对应的文件夹下,springboot才能自动扫描,否则需要:

@SpringBootApplication(scanBasePackages = "") //此处添加要扫面的controller
public class MainApplication {
    public static void main(String[] args) throws Exception{
        SpringApplication.run(MainApplication.class,args);
    }
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值