springmvc配置thymleaf视图解析器前端拿不到数据可能没有正确配置

导入依赖:

<dependency>

<groupId>org.thymeleaf</groupId>

<artifactId>thymeleaf</artifactId>

<version>3.0.9.RELEASE</version>

</dependency>

<dependency>

<groupId>org.thymeleaf</groupId>

<artifactId>thymeleaf-spring4</artifactId>

<version>3.0.9.RELEASE</version>

</dependency>

<?xml version="1.0" encoding="UTF-8"?>

配置web.xml绑定的文件

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context

https://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/mvc

" target="_blank">https://www.springframework.org/schema/mvc/spring-mvc.xsd">

<!-- 自动扫描包,让指定包下的注解生效,由IOC容器统一管理 -->

<context:component-scan base-package="com.kuang.controller"/>

<!-- 让Spring MVC不处理静态资源 -->

<mvc:default-servlet-handler />

<!--

支持mvc注解驱动

在spring中一般采用@RequestMapping注解来完成映射关系

要想使@RequestMapping注解生效

必须向上下文中注册DefaultAnnotationHandlerMapping

和一个AnnotationMethodHandlerAdapter实例

这两个实例分别在类级别和方法级别处理。

而annotation-driven配置帮助我们自动完成上述两个实例的注入。

-->

<mvc:annotation-driven />

<!--配置Thymeleaf视图解析器-->

<bean id="viewResolver" class="org.thymeleaf.spring4.view.ThymeleafViewResolver">

<property name="order" value="1"/>

<property name="characterEncoding" value="UTF-8"/>

<property name="templateEngine" ref="templateEngine"/>

</bean>

<!-- templateEngine -->

<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">

<property name="templateResolver" ref="templateResolver"/>

</bean>

<bean id="templateResolver" class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">

<property name="prefix" value="/WEB-INF/templates/"/>

<property name="suffix" value=".html"/>

<property name="templateMode" value="HTML5"/>

</bean>

</beans>

这番配置,前端也能够拿到后端传来的数据

特别注意需要配置xmlnsth:th=那一行才能被被识别。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值