集成mybatis和改造maven

dev
IT-xiaoXiong 2021-12-16 12:59:01 +08:00
parent 222fb66a41
commit d4176b69c4
8 changed files with 97 additions and 7 deletions

8
.gitignore vendored
View File

@ -17,10 +17,10 @@ log
*.apk
classbeanLib/*
weaverLib/*
web/**/*.properties
web/**/*.xml
target
classbean
/web/**/*.properties
/web/**/*.xml
/target
/classbean
.idea/
!/web/WEB-INF/prop/prop2map/*.properties
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`

View File

@ -100,6 +100,15 @@
</configuration>
</plugin>
</plugins>
<!-- <resources>-->
<!-- <resource>-->
<!-- <directory>test/mybatisTest</directory>-->
<!-- <includes>-->
<!-- <include>**/*.xml</include>-->
<!-- </includes>-->
<!-- <filtering>true</filtering>-->
<!-- </resource>-->
<!-- </resources>-->
</build>
</project>

View File

@ -0,0 +1,36 @@
package aiyh.utils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionManager;
import java.io.File;
import java.io.Reader;
/**
* @author EBU7-dev1-ayh
* create 2021/12/14 0014 15:57
*/
public class MybatisUtil {
private static SqlSessionManager sqlSessionManager = null;
private synchronized static void init(String config){
try {
Reader resourceAsReader = Resources.getResourceAsReader("WEB-INF" + File.separator +config);
sqlSessionManager = SqlSessionManager.newInstance(resourceAsReader);
} catch (Exception e) {
e.printStackTrace();
}
}
public static SqlSessionManager getSessionManager(String config){
if(sqlSessionManager == null){
synchronized (MybatisUtil.class) {
if (sqlSessionManager == null) {
init(config);
}
}
}
return sqlSessionManager;
}
}

View File

@ -46,7 +46,7 @@ import java.util.zip.ZipEntry;
/**
* @author EBU7-dev1-ayh
* @date 2021/8/23 0023 11:42
* dao
* mybatisTest.dao
*/

View File

@ -23,7 +23,7 @@ import java.util.Map;
/**
* @author EBU7-dev1-ayh
* @create 2021/8/26 0026 11:14
* copy dao
* copy mybatisTest.dao
*/

View File

@ -30,6 +30,7 @@ import java.util.Map;
*/
@Path("/v2/fadada")
public class FaDDContractController {
private final FaDDContractService faDDService = new FaDDContractService();
private final FaDDContractMapping faDDContractMapping = new FaDDContractMapping();
private final ToolUtil toolUtil = new ToolUtil();

View File

@ -10,7 +10,7 @@ import java.util.Objects;
/**
* @author EBU7-dev1-ayh
* @create 2021/8/10 0010 10:42
* dao class
* mybatisTest.dao class
*/

View File

@ -0,0 +1,44 @@
package mybatisTest;
import aiyh.utils.MybatisUtil;
import baseTest.BaseTest;
import mybatisTest.dao.ITestDAO;
import mybatisTest.entity.License;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.session.SqlSessionManager;
import org.junit.Test;
import java.io.Reader;
/**
* @author EBU7-dev1-ayh
* create 2021/12/14 0014 12:52
*/
public class MybatisTest extends BaseTest {
//查询
@Test
public void testName() throws Exception{
SqlSession session = null;
Reader resourceAsReader = Resources.getResourceAsReader("WEB-INF/test-mybatis-config.xml");
SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsReader);
session = build.openSession();
ITestDAO mapper = session.getMapper(ITestDAO.class);
// Map<String, String> map = mapper.selectOne();
// System.err.println(map);
session.close();
}
@Test
public void test(){
SqlSessionManager sessionManager = MybatisUtil.getSessionManager("test-mybatis-config.xml");
ITestDAO mapper = sessionManager.getMapper(ITestDAO.class);
License license = mapper.selectOne();
System.out.println(license);
}
}