(学习笔记)SpringMVC Web项目中Thymeleaf配置

三步

1.配置TemplateResolver

2.配置SpringTemplateEngine

3.配置ViewResolver

代码:

@Bean
public ViewResolver viewResolver(SpringTemplateEngine engine) {
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setCharacterEncoding("UTF-8");//设置编码
    resolver.setTemplateEngine(engine);
    return resolver;
}

@Bean
public SpringTemplateEngine engine(TemplateResolver resolver) {
    SpringTemplateEngine engine = new SpringTemplateEngine();
    engine.setTemplateResolver(resolver);
    return engine;
}

@Bean
public TemplateResolver templateResolver() {
    TemplateResolver resolv
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
整合Thymeleaf和Element-UI,需要在SpringMVC项目配置Thymeleaf模板引擎和Element-UI前端框架。 首先,在Spring MVC项目引入Thymeleaf和Element-UI的依赖。可以在pom.xml文件添加以下依赖: ```xml <dependencies> <!-- Thymeleaf --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!-- Element-UI --> <dependency> <groupId>org.webjars</groupId> <artifactId>webjars-locator-core</artifactId> <version>0.40</version> </dependency> <dependency> <groupId>org.webjars</groupId> <artifactId>element-ui</artifactId> <version>2.10.1</version> </dependency> </dependencies> ``` 然后,在Spring MVC配置文件配置Thymeleaf模板引擎。可以在application.properties或application.yml文件添加以下配置: ```properties # Thymeleaf spring.thymeleaf.mode=HTML spring.thymeleaf.cache=false spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.servlet.content-type=text/html;charset=UTF-8 spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.suffix=.html spring.thymeleaf.template-resolver-order=1 spring.thymeleaf.view-names=* spring.thymeleaf.check-template-location=true ``` 最后,在Thymeleaf模板使用Element-UI的组件。可以在HTML文件添加以下代码: ```html <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org" xmlns:t="http://www.thymeleaf.org/extras/thymeleaf-spring4" xmlns:el="http://www.thymeleaf.org/extras/element-ui" lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <!-- Element-UI --> <link rel="stylesheet" href="/webjars/element-ui/2.10.1/theme-chalk/index.css"> <script src="/webjars/element-ui/2.10.1/index.js"></script> </head> <body> <!-- 使用Element-UI的组件 --> <el-button>Button</el-button> </body> </html> ``` 以上就是整合Thymeleaf和Element-UI的步骤,希望能对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值