標籤:source driver val 3.2 blog back path llb crm
做了一個屏蔽進資料庫的操作:
Applicaition.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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd"> <!-- 配置資料來源,記得去掉myBatis-config.xml的資料來源相關配置 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="com.mysql.jdbc.Driver" /> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/mybatis2?useUnicode=true&characterEncoding=UTF-8" /> <property name="user" value="root" /> <property name="password" value="123456" /> </bean> <!-- 配置session工廠 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:mybatis-config.xml" /> </bean> <!-- 配置交易管理員,管理資料來源交易處理 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- 配置事務通知 --> <tx:advice id="advice" transaction-manager="transactionManager"> <tx:attributes> <!-- 預設只處理運行時異常,可加rollback-for="Exception/Throwable"等處理所有異常或包括錯誤 --> <tx:method name="insert*" propagation="REQUIRED" rollback-for="Exception" /> <tx:method name="update*" propagation="REQUIRED" rollback-for="Exception" /> <tx:method name="delete*" propagation="REQUIRED" rollback-for="Exception" /> <tx:method name="*" propagation="SUPPORTS" /> </tx:attributes> </tx:advice> <!-- 配置SessionTemplate,已封裝了繁瑣的資料操作 --> <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate" scope="prototype"> <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory" /> </bean> <!-- 配置切面織入的範圍,後邊要把事務邊界定在service層 --> <aop:config> <aop:advisor advice-ref="advice" pointcut="execution(* com.liuyang.crm.service.Imp.*.*(..))" /> </aop:config> <context:component-scan base-package="com.liuyang" /> <!--context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan --></beans>
防止錯誤資料進入的屏蔽
<context:component-scan base-package="com.liuyang" /> <!--context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan -->
這裡其實登出掉,也是好使的.加上了就出現文章上邊的找不到url地址注入的錯誤.
spring-mvc.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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd "> <!-- 同時開啟json格式的支援 --> <mvc:annotation-driven></mvc:annotation-driven> <context:component-scan base-package="com.liuyang"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" /> </context:component-scan></beans>
這裡配置屏蔽就可以,這樣資料庫同樣不進錯誤資料.
<context:component-scan base-package="com.liuyang"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" /> </context:component-scan>
@Overridepublic int insertDept(Dept dept) throws Exception {int i = 0;i = deptDao.insertDept(dept);Integer.parseInt("aa");return i;}
希望對您有協助,感謝您的觀看.
SpringMVC的問題No mapping found for HTTP request with URI