Projects are projects that use Spring + mybatis
Below is the configuration how to write:
This is written in spring:
<Jdbc:embedded-databaseID= "DataSource"> <Jdbc:script Location= "Classpath:/test/vmdb.script"/> </Jdbc:embedded-database>--The key is this sentence<BeanID= "Sqlsessionfactory"class= "Org.mybatis.spring.SqlSessionFactoryBean"> <!--when instantiating sqlsessionfactory, you need to use the above configured data sources and SQL mapping files. - < Propertyname= "DataSource"ref= "DataSource" /> < Propertyname= "Mapperlocations"value= "Classpath:com/suning/rdrs/admin/mapping/*.xml" /> </Bean> <!--Configuring the Scanner - <Beanclass= "Org.mybatis.spring.mapper.MapperScannerConfigurer"> <!--Scan Com.suning.rdrs.admin.dao All mapped interface classes under this package and its sub-packages - < Propertyname= "Basepackage"value= "Com.suning.rdrs.admin.dao" /> < Propertyname= "Sqlsessionfactorybeanname"value= "Sqlsessionfactory" /> </Bean>
How to construct the memory database for unit tests
PrivateConnection Conn; @Before Public voidbefore () {//Create a spring context using the two configuration files "Spring.xml" and "Spring-mybatis.xml"ApplicationContext AC =NewClasspathxmlapplicationcontext (Newstring[]{"/test/spring.xml", "/test/conf.xml"}); //Remove the UserService object we want to use from the spring container based on the Bean's IDUserService = (itaskservice) ac.getbean ("Taskservice"); Try{conn= Drivermanager.getconnection ("Jdbc:hsqldb:mem:rdrs", "sa", "" "); Startup memory Database RDRs, user name sa password empty}Catch(SQLException e) {}}
Also posted script statements, although known as compatible, but not so good compatibility
Incompatible with INDEX Index_taskname (taskname,username)
Column_pair text Character set UTF8, text specified character set incompatible
SET DATABASE SQL SYNTAX MYS TRUE; --compatible with mysqlcreate TABLE TASK ( ID INT (TEN) NOT NULL auto_increment, taskname varchar () is not NULL, USERNAME var char () not NULL, STATUS varchar (+) NOT NULL, task_type varchar (+) NOT NULL, gmt_create varchar (+) not N ULL, gmt_start varchar (n) not NULL, PRIMARY KEY (ID),);
The rest is simply MyBatis, the unit test is very good to write
How to use HSQLDB and mybatis to construct unit tests