|
@@ -16,10 +16,10 @@
|
|
package com.baomidou.mybatisplus.test.mysql;
|
|
package com.baomidou.mybatisplus.test.mysql;
|
|
|
|
|
|
import com.baomidou.mybatisplus.MybatisSessionFactoryBuilder;
|
|
import com.baomidou.mybatisplus.MybatisSessionFactoryBuilder;
|
|
|
|
+import com.baomidou.mybatisplus.test.mysql.entity.Test;
|
|
import com.baomidou.mybatisplus.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.toolkit.IdWorker;
|
|
import org.apache.ibatis.session.SqlSession;
|
|
import org.apache.ibatis.session.SqlSession;
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
-import org.junit.Test;
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
@@ -30,47 +30,31 @@ import java.util.Map;
|
|
* <p>
|
|
* <p>
|
|
* 测试没有XML同样注入CRUD SQL
|
|
* 测试没有XML同样注入CRUD SQL
|
|
* </p>
|
|
* </p>
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @author Caratacus
|
|
* @author Caratacus
|
|
* @date 2016-09-26
|
|
* @date 2016-09-26
|
|
*/
|
|
*/
|
|
public class NoXMLTest {
|
|
public class NoXMLTest {
|
|
- private SqlSession sqlSession;
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ /*
|
|
|
|
+ * 加载配置文件
|
|
|
|
+ */
|
|
InputStream in = NoXMLTest.class.getClassLoader().getResourceAsStream("mysql-config.xml");
|
|
InputStream in = NoXMLTest.class.getClassLoader().getResourceAsStream("mysql-config.xml");
|
|
MybatisSessionFactoryBuilder mf = new MybatisSessionFactoryBuilder();
|
|
MybatisSessionFactoryBuilder mf = new MybatisSessionFactoryBuilder();
|
|
SqlSessionFactory sessionFactory = mf.build(in);
|
|
SqlSessionFactory sessionFactory = mf.build(in);
|
|
- sqlSession = sessionFactory.openSession();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 测试ByMap忽略null
|
|
|
|
- */
|
|
|
|
- @Test
|
|
|
|
- public void test1() {
|
|
|
|
|
|
+ SqlSession sqlSession = sessionFactory.openSession();
|
|
/**
|
|
/**
|
|
* 查询是否有结果
|
|
* 查询是否有结果
|
|
*/
|
|
*/
|
|
TestMapper testMapper = sqlSession.getMapper(TestMapper.class);
|
|
TestMapper testMapper = sqlSession.getMapper(TestMapper.class);
|
|
|
|
+ testMapper.insert(new Test(IdWorker.getId(), "Caratacus"));
|
|
Map<String, Object> map = new HashMap();
|
|
Map<String, Object> map = new HashMap();
|
|
map.put("type", null);
|
|
map.put("type", null);
|
|
map.put("id", null);
|
|
map.put("id", null);
|
|
- System.out.println(testMapper.selectByMap(map));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 测试没有XML注入CRUD
|
|
|
|
- */
|
|
|
|
- @Test
|
|
|
|
- public void test2() {
|
|
|
|
- /**
|
|
|
|
- * 查询是否有结果
|
|
|
|
- */
|
|
|
|
- TestMapper testMapper = sqlSession.getMapper(TestMapper.class);
|
|
|
|
- testMapper.insert(new com.baomidou.mybatisplus.test.mysql.entity.Test(IdWorker.getId(), "Caratacus"));
|
|
|
|
- List<com.baomidou.mybatisplus.test.mysql.entity.Test> tests = testMapper.selectList(null);
|
|
|
|
|
|
+ List<Test> tests = testMapper.selectByMap(map);
|
|
if (null != tests) {
|
|
if (null != tests) {
|
|
- for (com.baomidou.mybatisplus.test.mysql.entity.Test test : tests) {
|
|
|
|
|
|
+ for (Test test : tests) {
|
|
System.out.println("id:"+test.getId()+ " , type:" + test.getType());
|
|
System.out.println("id:"+test.getId()+ " , type:" + test.getType());
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|