Skip to content

Commit

Permalink
mybatis-plus demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ningpp committed Aug 17, 2024
1 parent dd286a5 commit ebbc538
Show file tree
Hide file tree
Showing 11 changed files with 591 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,20 @@
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
</context>
<context id="mybatis_plus_demo" targetRuntime="me.ningpp.mmegp.codegen.GenerateNothingIntrospectedTableImpl">
<property name="introspectedTableBuilder" value="me.ningpp.mmegp.mybatisplus.generator.MyBatisPlusIntrospectedTableBuilder" />
<plugin type="me.ningpp.mmegp.plugins.GenerateDynamicSqlSupportClassPlugin">
<property name="targetProject" value="target/generated-sources/mme/java" />
</plugin>
<commentGenerator type="me.ningpp.mmegp.comment.WithoutGeneratedAnnotationCommentGenerator">
<property name="suppressAllComments" value="true" />
</commentGenerator>
<javaModelGenerator targetPackage="me.ningpp.mmegp.demo.mybatisplus" >
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="false" />
</javaModelGenerator>
<javaClientGenerator type="MIXEDMAPPER" targetPackage="me.ningpp.mmegp.demo.mybatisplusmapper">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
</context>
</generatorConfiguration>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<artifactId>mmegp-maven-plugin-demo-xmlmapper</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-annotation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
Expand Down Expand Up @@ -88,6 +92,13 @@
<groupId>io.github.ningpp</groupId>
<artifactId>mmegp-maven-plugin</artifactId>
<version>${project.version}</version>
<dependencies>
<dependency>
<groupId>io.github.ningpp</groupId>
<artifactId>mmegp-mybatis-plus</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<configuration>
<generatorConfigFilePath>${basedir}/mmegpGeneratorConfig.xml</generatorConfigFilePath>
<customCompileSourceRoots>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2021-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.ningpp.mmegp.demo.mybatisplus;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

@TableName
public class MybatisPlusEntity {

@TableId(type = IdType.AUTO)
private Integer id;

private String title;

@TableField("mp_content")
private String content;

@TableField(exist = false)
private String notExistColumn;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public String getNotExistColumn() {
return notExistColumn;
}

public void setNotExistColumn(String notExistColumn) {
this.notExistColumn = notExistColumn;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2021-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.ningpp.mmegp.demo.mybatisplus;

import me.ningpp.mmegp.demo.mybatisplusmapper.MybatisPlusEntityDynamicSqlSupport;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static me.ningpp.mmegp.demo.mybatisplusmapper.MybatisPlusEntityDynamicSqlSupport.content;
import static me.ningpp.mmegp.demo.mybatisplusmapper.MybatisPlusEntityDynamicSqlSupport.id;
import static me.ningpp.mmegp.demo.mybatisplusmapper.MybatisPlusEntityDynamicSqlSupport.mybatisPlusEntity;
import static me.ningpp.mmegp.demo.mybatisplusmapper.MybatisPlusEntityDynamicSqlSupport.title;
import static org.junit.jupiter.api.Assertions.assertEquals;

class MybatisPlusEntityTest {

@Test
void parseTest() {
assertEquals("id", id.name());
assertEquals("title", title.name());
assertEquals("mp_content", content.name());
assertEquals("mybatis_plus_entity", mybatisPlusEntity.tableNameAtRuntime());
Field[] fields = MybatisPlusEntityDynamicSqlSupport.MybatisPlusEntity.class.getFields();
// 需要禁止掉jacoco
assertEquals("id,title,content",
Stream.of(fields).map(Field::getName).collect(Collectors.joining(",")));
}

}
12 changes: 12 additions & 0 deletions mmegp-maven-plugin-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

</project>
Loading

0 comments on commit ebbc538

Please sign in to comment.