侧边栏壁纸
  • 累计撰写 101 篇文章
  • 累计创建 89 个标签
  • 累计收到 9 条评论

springBoot中使用layui不显示图标

bearjun
2021-03-04 / 0 评论 / 0 点赞 / 2,544 阅读 / 3,065 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-04-17,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

背景

最近做项目,用到了layui,但是在搭建的时候,layui的原生图标都不显示,显示的小方块。

原因

这是因为经过maven的filter,会破坏font文件的二进制文件格式,所以前台解析出错

解决

在maven的插件中加入一下代码

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-resources-plugin</artifactId>
   <configuration>
        <nonFilteredFileExtensions>
             <nonFilteredFileExtension>woff</nonFilteredFileExtension>
             <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
             <nonFilteredFileExtension>eot</nonFilteredFileExtension>
             <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
             <nonFilteredFileExtension>svg</nonFilteredFileExtension>
         </nonFilteredFileExtensions>
    </configuration>
</plugin>
<resource>			 
     <directory>${project.basedir}/src/main/resources</directory>
     <filtering>true</filtering>
     <excludes>
        <exclude>**/*.woff</exclude>
        <exclude>**/*.woff2</exclude>
        <exclude>**/*.ttf</exclude>
    </excludes>
</resource>
<resource>
    <directory>${project.basedir}/src/main/resources</directory>
    <filtering>false</filtering>
    <includes>
        <include>**/*.woff</include>
        <include>**/*.woff2</include>
        <include>**/*.ttf</include>
    </includes>
</resource>

完整的pom.xml

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
	<!--如下添加以防乱码-->
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <configuration>
                        <nonFilteredFileExtensions>
                            <nonFilteredFileExtension>woff</nonFilteredFileExtension>
                            <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
                            <nonFilteredFileExtension>eot</nonFilteredFileExtension>
                            <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
                            <nonFilteredFileExtension>svg</nonFilteredFileExtension>
                        </nonFilteredFileExtensions>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <resources>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>**/*.woff</exclude>
                    <exclude>**/*.woff2</exclude>
                    <exclude>**/*.ttf</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
                <filtering>false</filtering>
                <includes>
                    <include>**/*.woff</include>
                    <include>**/*.woff2</include>
                    <include>**/*.ttf</include>
                </includes>
            </resource>
        </resources>
    </build>

清除缓存并且重启idea,一定要重启idea。

0

评论区