Browse Source

添加无 xml 注解测试

jobob 8 năm trước cách đây
mục cha
commit
48942dc24f

+ 3 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/NoXMLTest.java

@@ -17,6 +17,8 @@ package com.baomidou.mybatisplus.test.mysql;
 
 import com.baomidou.mybatisplus.MybatisSessionFactoryBuilder;
 import com.baomidou.mybatisplus.test.mysql.entity.Test;
+import com.baomidou.mybatisplus.toolkit.IdWorker;
+
 import org.apache.ibatis.session.SqlSession;
 import org.apache.ibatis.session.SqlSessionFactory;
 
@@ -45,6 +47,7 @@ public class NoXMLTest {
 		 * 查询是否有结果
 		 */
 		TestMapper testMapper = sqlSession.getMapper(TestMapper.class);
+		testMapper.insert(new Test(IdWorker.getId(), "Caratacus"));
 		List<Test> tests = testMapper.selectList(null);
 		if (null != tests) {
 			for (Test test : tests) {

+ 9 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/TestMapper.java

@@ -15,6 +15,8 @@
  */
 package com.baomidou.mybatisplus.test.mysql;
 
+import org.apache.ibatis.annotations.Insert;
+
 import com.baomidou.mybatisplus.mapper.AutoMapper;
 import com.baomidou.mybatisplus.test.mysql.entity.Test;
 
@@ -23,9 +25,15 @@ import com.baomidou.mybatisplus.test.mysql.entity.Test;
  * 继承 AutoMapper,就自动拥有CRUD方法
  * </p>
  * 
- * @author Caratacus
+ * @author Caratacus hubin
  * @Date 2016-09-25
  */
 public interface TestMapper extends AutoMapper<Test> {
 
+	/**
+	 * 注解插入【测试】
+	 */
+	@Insert("insert into test(id,type) values(#{id},#{type})")
+	int insertInjector(Test test);
+
 }

+ 9 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/Test.java

@@ -41,6 +41,15 @@ public class Test implements Serializable {
 
 	private String type;
 
+	public Test() {
+
+	}
+
+	public Test(Long id, String type) {
+		this.id = id;
+		this.type = type;
+	}
+
 	public Long getId() {
 		return id;
 	}