目录结构为
WEB-INF
-Pages
----manager
package cn.nazii.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("Manager")
public class ManagerController {
@RequestMapping("/index")
public String LoginAction()
{
return "manager/index";
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--开启只对controller的扫描-->
<context:component-scan base-package="cn.nazii.controller">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<mvc:default-servlet-handler/>
<!--配置视图解析器-->
<bean id="org" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!--JSP 目录-->
<property name="prefix" value="/WEB-INF/pages/"/>
<!--文件后缀-->
<property name="suffix" value=".jsp"/>
</bean>
<!--不过滤静态资源-->
<mvc:resources mapping="static/**" location="static/"/>
<mvc:resources mapping="static/css/**" location="static/css/"/>
<mvc:resources mapping="static/images/**" location="static/images/"/>
<mvc:resources mapping="static/js/**" location="static/js/"/>
<mvc:resources mapping="static/element/**" location="static/element/"/>
<mvc:resources mapping="static/api/**" location="static/api/"/>
<mvc:resources mapping="static/lib/**" location="static/lib/"/>
<!--开启注解支持-->
<mvc:annotation-driven/>
<!-- 文件上传 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8" />
<property name="maxUploadSize" value="1048576000000" />
<property name="maxInMemorySize" value="40960" />
</bean>
</beans>
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:component-scan base-package="cn.nazii">
<!-- 配置哪些注解不扫描 -->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 加载配置文件 *.properties -->
<context:property-placeholder
location="classpath:jdbcConfig.properties"/>
<!--配置数据库 dataSource -->
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 加载数据库用户名 -->
<property name="driverClass" value="${jdbc.driver}"/>
<!-- 加载数据库密码 -->
<property name="jdbcUrl" value="${jdbc.url}"/>
<!-- 加载数据库连接 -->
<property name="user" value="${jdbc.username}"/>
<!-- 加载数据库驱动 -->
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- 配置sqlsessioFactory -->
<bean id="sqlSessionFactoryBean"
class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 配置数据源 引用(ref)dataSource(bean) -->
<property name="dataSource" ref="dataSource"/>
<!-- 加载mybatis 配置文件 -->
<!-- <property name="configLocation"-->
<!-- value="classpath:mybatis/mybatis.xml"/>-->
<!-- <property name="mapperLocations" value="classpath:cn/nazii/mapper/*Mapper.xml"/>-->
</bean>
<!-- 扫描注解 -->
<bean id="manager" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="cn.nazii.dao"/>
</bean>
<!--配置AccountDao接口所在包-->
<bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="cn.nazii.dao"/>
</bean>
<!-- 扫描Service包 -->
<context:component-scan
base-package="cn.nazii.service"/>
<!--配置spring声明式事务管理-->
<!--配置事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--配置事务通知-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!--所有find开头(查询)的方法设置只读-->
<tx:method name="find*" read-only="true"/>
<!--事务的隔离级别,默认default-->
<tx:method name="*" isolation="DEFAULT"/>
</tx:attributes>
</tx:advice>
<!--配置aop增强-->
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* cn.nazii.service.impl.*.*(..))"></aop:advisor>
</aop:config>
</beans>