集成mybatis和改造maven
parent
222fb66a41
commit
d4176b69c4
|
@ -17,10 +17,10 @@ log
|
||||||
*.apk
|
*.apk
|
||||||
classbeanLib/*
|
classbeanLib/*
|
||||||
weaverLib/*
|
weaverLib/*
|
||||||
web/**/*.properties
|
/web/**/*.properties
|
||||||
web/**/*.xml
|
/web/**/*.xml
|
||||||
target
|
/target
|
||||||
classbean
|
/classbean
|
||||||
.idea/
|
.idea/
|
||||||
!/web/WEB-INF/prop/prop2map/*.properties
|
!/web/WEB-INF/prop/prop2map/*.properties
|
||||||
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`
|
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`
|
||||||
|
|
9
pom.xml
9
pom.xml
|
@ -100,6 +100,15 @@
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
<!-- <resources>-->
|
||||||
|
<!-- <resource>-->
|
||||||
|
<!-- <directory>test/mybatisTest</directory>-->
|
||||||
|
<!-- <includes>-->
|
||||||
|
<!-- <include>**/*.xml</include>-->
|
||||||
|
<!-- </includes>-->
|
||||||
|
<!-- <filtering>true</filtering>-->
|
||||||
|
<!-- </resource>-->
|
||||||
|
<!-- </resources>-->
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,7 +46,7 @@ import java.util.zip.ZipEntry;
|
||||||
/**
|
/**
|
||||||
* @author EBU7-dev1-ayh
|
* @author EBU7-dev1-ayh
|
||||||
* @date 2021/8/23 0023 11:42
|
* @date 2021/8/23 0023 11:42
|
||||||
* dao 工具类
|
* mybatisTest.dao 工具类
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ import java.util.Map;
|
||||||
/**
|
/**
|
||||||
* @author EBU7-dev1-ayh
|
* @author EBU7-dev1-ayh
|
||||||
* @create 2021/8/26 0026 11:14
|
* @create 2021/8/26 0026 11:14
|
||||||
* copy dao
|
* copy mybatisTest.dao
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
@Path("/v2/fadada")
|
@Path("/v2/fadada")
|
||||||
public class FaDDContractController {
|
public class FaDDContractController {
|
||||||
|
|
||||||
private final FaDDContractService faDDService = new FaDDContractService();
|
private final FaDDContractService faDDService = new FaDDContractService();
|
||||||
private final FaDDContractMapping faDDContractMapping = new FaDDContractMapping();
|
private final FaDDContractMapping faDDContractMapping = new FaDDContractMapping();
|
||||||
private final ToolUtil toolUtil = new ToolUtil();
|
private final ToolUtil toolUtil = new ToolUtil();
|
||||||
|
|
|
@ -10,7 +10,7 @@ import java.util.Objects;
|
||||||
/**
|
/**
|
||||||
* @author EBU7-dev1-ayh
|
* @author EBU7-dev1-ayh
|
||||||
* @create 2021/8/10 0010 10:42
|
* @create 2021/8/10 0010 10:42
|
||||||
* dao class
|
* mybatisTest.dao class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue