目錄結構
在是springmvc.xml
文件下開啓過濾靜態資源
<?xml version="1.0" encoding="UTF-8"?>
<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 http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--開啓註解掃描,只掃描controller-->
<context:component-scan base-package="club.twzw">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!--配置視圖解析器-->
<bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="suffix" value=".jsp"/>
<property name="prefix" value="/WEB-INF/views/"/>
</bean>
<!--過濾靜態資源-->
<mvc:resources mapping="/layui/**" location="WEB-INF/layui/"/>
<!-- <mvc:resources mapping="/font/**" location="/font/"/>-->
<!-- <mvc:resources mapping="/images/**" location="/images/"/>-->
<!-- <mvc:resources mapping="/lay/**" location="/lay/"/>-->
<!-- <mvc:resources mapping="/js/**" location="/js/"/>-->
<!--開啓springmvc註解支持-->
<mvc:annotation-driven/>
</beans>
頁面引用
<link rel="stylesheet" href="layui/css/layui.css">
<script src="layui/layui.js"></script>
最終效果