ssm配置复制粘贴用

applicationContext-Dao:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.springframework.org/schema/beans" 
        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-4.2.xsd 
                            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd 
                            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd 
                            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd ">
<!-- 读取数据库配置文件 -->
<context:property-placeholder location="classpath:db.properties"/>

<!-- 数据源 -->
<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
    <property name="driverClassName" value="${jdbc.driverClass}"></property>
    <property name="url" value="${jdbc.jdbcUrl}"></property>
    <property name="username" value="${jdbc.user}"></property>
    <property name="password" value="${jdbc.password}"></property>
</bean>

<!-- session工厂 -->
<bean name="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <!-- 连接池 -->
    <property name="dataSource" ref="dataSource"></property>
    <!-- mybatis的配置文件信息 -->
    <property name="configLocation" value="classpath:sqlMapConfig.xml"></property>
</bean>

<!-- 扫描mapper接口和xml -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <!-- 扫描的基本包 -->
    <property name="basePackage" value="cn.itheima.mapper"></property>
</bean>

</beans>

 

springmvc.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/beans"
    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:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd">

<!-- 组件扫描 -->
<context:component-scan base-package="cn.itheima.controller"/>

<!-- 配置映射器 -->
<!-- 配置适配器 -->
<mvc:annotation-driven/>

<!-- 配置视图解析器 -->
<bean name="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <!-- 前缀 -->
    <!-- 后缀 -->
</bean>


</beans>

 

sqlMapConfig.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis/dtd/mybatis-3-config.dtd">

<configuration>
<!-- 设置settings全局 -->

<!-- 设置pojo类别名 -->
    <typeAliases>
        <package name="cn.itheima.pojo"/>
    </typeAliases>
    
<!-- 加载mapper.xml等,交给springmvc扫描完成 -->
    
</configuration>

 

mapper.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis/dtd/mybatis-3-mapper.dtd">

 

db.properties:

jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql:///xxx
jdbc.user=root
jdbc.password=123

 

上一篇:Linux有问必答:如何在Linux中修改环境变量PATH


下一篇:mybatis配置文件sqlMapConfig.xml