最近用mybatis开发,一些总结:
-
结合spring框架,需要在spring配置文件中加入sessionFactory定义:
? ? ? ??
<!-- 创建SqlSessionFactory,同时指定数据源 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:mybatis-config.xml"/> <property name="dataSource" ref="dataSource" /> </bean>
?
?
-
定义mybatis-config.xml文件
?
<?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> <typeAlias alias="App" type="com.cyou.appserver.entity.App"/> <typeAlias alias="Feedback" type="com.cyou.appserver.entity.Feedback"/> <typeAlias alias="RecommendApp" type="com.cyou.appserver.entity.RecommendApp"/> <typeAlias alias="UpdateInfo" type="com.cyou.appserver.entity.UpdateInfo"/> <typeAlias alias="DeviceToken" type="com.cyou.appserver.entity.DeviceToken"/> <typeAlias alias="Cards" type="com.cyou.appserver.entity.Cards"/> <typeAlias alias="UnableVideoLog" type="com.cyou.appserver.entity.UnableVideoLog"/> <typeAlias alias="Battle" type="com.cyou.appserver.entity.Battle"/> <typeAlias alias="Card" type="com.cyou.appserver.entity.Card"/> <typeAlias alias="Occupational" type="com.cyou.appserver.entity.Occupational"/> <typeAlias alias="Licensing" type="com.cyou.appserver.entity.Licensing"/> <typeAlias alias="Pictures" type="com.cyou.appserver.entity.Pictures"/> <typeAlias alias="Timetable" type="com.cyou.appserver.entity.Timetable"/> <typeAlias alias="IndexImage" type="com.cyou.appserver.entity.IndexImage"/> <typeAlias alias="CardStat" type="com.cyou.appserver.entity.CardStat"/> <typeAlias alias="AppPush" type="com.cyou.appserver.entity.AppPush" /> <typeAlias alias="Formation" type="com.cyou.appserver.entity.Formation" /> <typeAlias alias="FormationParise" type="com.cyou.appserver.entity.FormationParise" /> <!-- <typeAlias alias="AppConfig" type="com.cyou.appserver.entity.AppConfig"/> <typeAlias alias="AppMenus" type="com.cyou.appserver.entity.AppMenus"/> <typeAlias alias="AppClick" type="com.cyou.appserver.entity.AppClick"/>--> </typeAliases> <mappers> <mapper resource="mybatis/Ad.xml" /> <mapper resource="mybatis/App.xml" /> <mapper resource="mybatis/Feedback.xml" /> <mapper resource="mybatis/RecommendApp.xml" /> <mapper resource="mybatis/UpdateInfo.xml" /> <mapper resource="mybatis/DeviceToken.xml" /> <mapper resource="mybatis/Cards.xml" /> <mapper resource="mybatis/UnableVideoLog.xml" /> <mapper resource="mybatis/Battle.xml" /> <mapper resource="mybatis/Card.xml" /> <mapper resource="mybatis/Occupational.xml" /> <mapper resource="mybatis/Licensing.xml" /> <mapper resource="mybatis/Pictures.xml" /> <mapper resource="mybatis/Timetable.xml" /> <mapper resource="mybatis/IndexImage.xml" /> <mapper resource="mybatis/CardStat.xml" /> <mapper resource="mybatis/AppPush.xml" /> <!-- <mapper resource="mybatis/AppConfig.xml" /> <mapper resource="mybatis/AppMenus.xml" /> <mapper resource="mybatis/AppClick.xml" /> --> <mapper resource="mybatis/Formation.xml" /> <mapper resource="mybatis/FormationParise.xml" /> </mappers> </