Spring數據校驗(附代碼鏈接)

最後附有網盤鏈接(程序打包+數據庫)

Spring數據校驗

所有的文件,包含靜態資源文件都交給spring mvc處理。就需要用到<mvc:annotation-driven />了。如果不加,DispatcherServlet則無法區分請求是資源文件還是mvc的註解,而導致controller的請求報錯誤

在上下文中添加 mvc:annotation-driven</mvc:annotation-driven>

下面代碼的最後一行
文件名:/springmvc/src/main/resources/config/applicationContext-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:util="http://www.springframework.org/schema/util"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://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/aop
        https://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        https://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/mvc
        https://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/util
        http://www.springframework.org/schema/util/spring-util.xsd
        ">
    <context:component-scan base-package="init.wuji.springboot.mvc.*.action"></context:component-scan>    
	
	<!-- 
	配置視圖解析器
	 -->
	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/views/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>	
		
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!-- 上傳文件的最大值, 單位爲:字節  50*1024*1024 
		
		-->
		<property name="maxUploadSize" value="#{50*1024*1024}" />
	</bean>

	<mvc:annotation-driven></mvc:annotation-driven>	
</beans>

鏈接

鏈接:https://pan.baidu.com/s/1_8Hs6V06GdX7ia5fYV4MlQ
提取碼:7s8u

下課

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章