freemarker404解决方案(全面)

freemarker404解决方案

1,依赖问题

<!-- 引入freeMarker的依赖包. -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-freemarker</artifactId>
		</dependency>

img

记得刷新,可以双击点进去说明导入成功。或者在External Libraries中发现对应jar包

2.没有在.yml或者.properties中配置代码

//applicatioin.yml
freemarker:
    suffix: .ftl  #后缀名
//applicatioin.properties
spring.freemarker.suffix=.ftl

把templates放在resources下,把html后缀改成ftl

如:list.html 改成 list.ftl

3.注意路径问题

是网页上输入的网站和controller层自己写的是否正确

注意后台controller书写规范和前端页面书写规范,后台返回语句(return)的第一个是没有/

4.注意@Controller和@RestContoller注解使用

因为采用freemarker模板渲染,所以应该采用@Controller。

@RestContoller用来传JSON格式数据

5.pom.xml写了resources

因为我用的mybatis,所以在pom.xml写了resources(为了解决mybatis配置的问题)。

没想到有个导致freemarker404。

没改前:

<resources>
			<resource>
				<directory>src/main/resources</directory>
				<includes>
					<include>**/*.yml</include>
					<include>**/*.xml</include>					
				</includes>
				<filtering>true</filtering>
			</resource>
			<resource>
				<directory>src/main/java</directory>
				<includes>
					<include>**/*.yml</include>
					<include>**/*.xml</include>
				</includes>
				<filtering>true</filtering>
			</resource>
		</resources>

修改后成功解决问题:

加了**/*.ftl

<resources>
			<resource>
				<directory>src/main/resources</directory>
				<includes>
					<include>**/*.yml</include>
					<include>**/*.xml</include>
					<include>**/*.ftl</include>
				</includes>
				<filtering>true</filtering>
			</resource>
			<resource>
				<directory>src/main/java</directory>
				<includes>
					<include>**/*.yml</include>
					<include>**/*.xml</include>
				</includes>
				<filtering>true</filtering>
			</resource>
		</resources>

附上给我解决问题思路的链接。

https://blog.csdn.net/yousacks/article/details/107864000

posted @ 2021-03-10 16:34  Godwin_Zhang  阅读(580)  评论(0编辑  收藏  举报