SpringBoot集成thymeleaf(自定义)模板中文乱码的解决办法

阅读: 评论:0

SpringBoot集成thymeleaf(⾃定义)模板中⽂乱码解决
楼主今天在学习SpringBoot集成thymelaf的时候报了中⽂乱码的错误,经过⽹上的搜索,现在得到解决的办法,分享给⼤家:
package fig;
import org.springframework.beans.BeansException;
import org.t.properties.ConfigurationProperties;
import t.ApplicationContext;
import t.ApplicationContextAware;
import t.annotation.Bean;
import t.annotation.Configuration;
import org.springframework.fig.annotation.ResourceHandlerRegistry;
import org.springframework.fig.annotation.WebMvcConfigurerAdapter;
import org.thymeleaf.spring4.SpringTemplateEngine;
import org.plateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
/**
* WebMvc的配置类(⾃定义Thymeleaf模板)
*
* @author Liao Huan
*/
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware {
等离子体处理
private ApplicationContext applicationContext;
/**
* 设置上下⽂
*
* @param applicationContext
* @throws BeansException
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
/
**
* Thymeleaf模板资源解析器(⾃定义的需要做前缀绑定)
*/
@Bean
@ConfigurationProperties(prefix = "spring.thymeleaf")
public SpringResourceTemplateResolver templateResolver() {
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
templateResolver.setApplicationContext(this.applicationContext);
return templateResolver;
}
/**
* Thymeleaf标准⽅⾔解释器
*/
@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
//⽀持spring EL表达式
templateEngine.setEnableSpringELCompiler(true);
return templateEngine;
}
车载卫星电视}
/
**
* 视图解析器
*/
@Bean
public ThymeleafViewResolver thymeleafViewResolver() {
ThymeleafViewResolver thymeleafViewResolver = new ThymeleafViewResolver();
thymeleafViewResolver.setTemplateEngine(templateEngine());
return thymeleafViewResolver;
downlinker}
强力磁盘
我使⽤的是⾃定义的thymelefa模板,在配置⽂件中需要⼿动去配置上⾯的⼏个⽅法,这⾥给出thymeleaf部分配置⽂件和Controller类的截图代码:
大肠杆菌培养基
applicaiton.properties:
然后测试Controller:
下⾯是我的HTML代码:
启动项⽬之后:出现中⽂乱码烘干炉
解决办法如下图:(在最上⾯的配置⽂件相应位置加上下图红⾊箭头部分的代码)
重启项⽬即可解决中⽂乱码问题:

本文发布于:2023-06-19 21:19:38,感谢您对本站的认可!

本文链接:https://patent.en369.cn/patent/3/145160.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:解决   定义   配置   乱码
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 369专利查询检索平台 豫ICP备2021025688号-20 网站地图