SSM框架整合之配置文件的定义
2018-02-19 09:33
666 查看
SSM框架整合之配置文件的定义
一、mybatis所需要的配置文件
1,mybatis映射文件
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="接口的全限定性名称"> <insert id="对应的方法名称"> <!-- sql语句--> insert into student(name,age) values(#{name},#{age}) </insert> </mapper>
2,mybatis主配置文件
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 为实体类指定别名 --> <typeAliases> <package name="com.bjpowernode.beans"/> </typeAliases> <!-- 注册映射文件 --> <mappers> <!-- 映射文件的名字和实体类的名字相同的时候才能这样写 要是不同,就要用 mapper标签--> <package name="com.bjpowernode.dao"/> </mappers> </configuration>
二、Spring框架所需配置文件
1,Spring-db
<?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/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 注册C3P0数据源 --> <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.user}"/> <property name="password" value="${jdbc.password}"/> </bean> <!-- 注册属性文件 --> <context:property-placeholder location="classpath:resources/jdbc.properties"/> </beans>
2,Spring-mybatis
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.o 4000 rg/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/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 注册SqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:resources/mybatis.xml"/> <property name="dataSource" ref="dataSource"/> </bean> <!-- 生成Dao的代理对象 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> <property name="basePackage" value="com.bjpowernode.dao"/> </bean> </beans>
3,Spring-Service
<?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/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 注册Service --> <bean id="studentService" class="com.bjpowernode.service.StudentServiceImpl"> <property name="dao" ref="IStudentDao"/> </bean> </beans>
4,Spring-tx
<?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/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 注册切面 --> <bean id="myAspect" class="com.bjpowernode.aspect.MyAspect"/> <!-- 注册目标对象 --> <bean id="studentService" class="com.bjpowernode.service.StudentServiceImpl"/> <!-- 注册事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!-- 注册事务通知 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" isolation="DEFAULT" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <!-- AOP配置 --> <aop:config> <aop:pointcut expression="execution(* *..service.*.*(..))" id="studentPointcut"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="studentPointcut"/> <aop:aspect ref="myAspect"> <aop:before method="myBefore" pointcut-ref="studentPointcut"/> </aop:aspect> </aop:config> </beans>
三、SpringMVC所需配置
<?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/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 注册处理器 --> <bean id="/test/register.do" class="com.bjpowernode.handlers.StudentController"> <property name="service" ref="studentService"/> </bean> </beans>
四、其他配置文件
1,jdbc.properties
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1:3306/test jdbc.user=root jdbc.password=161360238
相关文章推荐
- Spring需要的几个关键配置文件(SSM框架整合)
- SSM框架整合开发的文件配置
- Maven整合SSM框架相关的配置文件
- 【SSM框架整合】配置文件的配置
- 整合ssm框架之配置文件
- 最基础的-----基于maven进行的SSM框架的整合的全部配置文件.
- SSM框架整合 配置文件
- ssm框架整合的配置文件applicationContext.xml
- maven-ssm框架基本整合之配置文件的配置
- SSM框架整合方式(一):XML配置文件代码
- SSM框架整合配置文件整理
- MVC设计模式/SpringMVC/SSM框架整合配置文件讲解
- SSM框架整合方式(二):XML配置文件代码
- SSM框架整合之Spring主配置文件的写法
- ssm组合框架所需的配置文件
- 搭建SSM框架的几大综合配置文件
- springmvc(二) ssm框架整合的各种配置
- SSM框架配置文件详解(图解)
- 如何搭建一个基于Java Config零配置的SSM框架(无配置文件)
- Mina框架与Spring整合配置文件