diff --git a/docs/en/md/dev-example/dao-basic.md b/docs/en/md/dev-example/dao-basic.md index 3e35d6fc..c44fb1ec 100644 --- a/docs/en/md/dev-example/dao-basic.md +++ b/docs/en/md/dev-example/dao-basic.md @@ -29,9 +29,8 @@ public class PersonServiceImpl { @Autowired private PersonDao dao; - // Regardless of whether the attribute is empty or not, - // if there is a corresponding ID value in the database, - // other properties will be overwritten + //If there is already a corresponding ID value + //the insert operation will not be performed. public void insert( Person person ) { dao.insert( person ); } diff --git a/ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/NebulaBasicDaoTests.java b/ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/NebulaBasicDaoTests.java index a816315c..b893c1a3 100644 --- a/ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/NebulaBasicDaoTests.java +++ b/ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/NebulaBasicDaoTests.java @@ -21,6 +21,7 @@ import org.nebula.contrib.ngbatis.utils.Page; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import ye.weicheng.ngbatis.demo.pojo.Employee; import ye.weicheng.ngbatis.demo.pojo.Like; import ye.weicheng.ngbatis.demo.pojo.LikeWithRank; import ye.weicheng.ngbatis.demo.pojo.Person; @@ -161,6 +162,7 @@ public void insertSelective() { Person person = new Person(); person.setAge(20); person.setName("王小冰"); + person.setGender(null); repository.insertSelective(person); } @@ -206,6 +208,56 @@ public void insertBatch() { repository.insertBatch(people); } + + @Test + public void insertSelectiveBatch() { + Person person1 = new Person(); + person1.setName("IB111"); + person1.setGender("M"); + person1.setAge(null); + + Person person2 = new Person(); + person2.setName("IB222"); + person2.setAge(18); + person2.setBirthday(new Date()); + + Person person3 = new Person(); + person3.setName("IB333"); + person3.setGender("M"); + person3.setBirthday(new Date()); + + List people = new ArrayList<>(); + people.add(person1); + people.add(person2); + people.add(person3); + + repository.insertSelectiveBatch(people); + } + + @Test + public void insertSelectiveBatchMultiTag() { + Employee employee1 = new Employee(); + employee1.setName("职员1"); + employee1.setGender("F"); + employee1.setPosition("后端"); + + Employee employee2 = new Employee(); + employee2.setName("职员2"); + employee2.setGender("M"); + employee2.setPosition("前端"); + + Employee employee3 = new Employee(); + employee3.setName("职员3"); + employee3.setGender("F"); + employee3.setPosition("测试"); + + List employees = new ArrayList<>(); + employees.add(employee1); + employees.add(employee2); + employees.add(employee3); + + repository.insertSelectiveBatch(employees); + } // endregion // region update zoom diff --git a/pom.xml b/pom.xml index 036fb5fb..60536397 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,10 @@ shbone 598924626@qq.com + + Ozjq + 2719530295@qq.com + diff --git a/src/main/java/org/nebula/contrib/ngbatis/proxy/NebulaDaoBasic.java b/src/main/java/org/nebula/contrib/ngbatis/proxy/NebulaDaoBasic.java index f77b0a90..4d89c3b2 100644 --- a/src/main/java/org/nebula/contrib/ngbatis/proxy/NebulaDaoBasic.java +++ b/src/main/java/org/nebula/contrib/ngbatis/proxy/NebulaDaoBasic.java @@ -219,6 +219,16 @@ default void insertBatch(List ts) { ClassModel classModel = getClassModel(this.getClass()); MapperProxy.invoke(classModel, methodModel, ts); } + + /** + * 批量插入非空字段 + * @param ts 当前Tag下多个顶点 + */ + default void insertSelectiveBatch(List ts){ + MethodModel methodModel = getMethodModel(); + ClassModel classModel = getClassModel(this.getClass()); + MapperProxy.invoke(classModel,methodModel,ts); + } // endregion // region update zoom diff --git a/src/main/resources/NebulaDaoBasic.xml b/src/main/resources/NebulaDaoBasic.xml index 3bda8fa9..f5e6e416 100644 --- a/src/main/resources/NebulaDaoBasic.xml +++ b/src/main/resources/NebulaDaoBasic.xml @@ -194,6 +194,22 @@ ${ id } : ( ${ ng.join( @kv.values ) } ) ${ rowLP.last ? '' : ', ' } @} + + + @for ( row in ng_args[0] ) { + @var kv = ng.kv( row, '', true, true ); + @var id = ng.id( row ); + INSERT VERTEX IF NOT EXISTS + @for ( entry in @kv.multiTagColumns ) { + `${ entry.key }` ( + ${ ng.join( entry.value, ", ", "ng.schemaFmt" ) } + ) ${ entryLP.last ? '' : ','} + @} + VALUES + ${ id } : ( ${ ng.join( @kv.values ) } ) ; + @} + +