diff --git a/pom.xml b/pom.xml index d91db11..a6faf71 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,11 @@ + + org.projectlombok + lombok + 1.18.30 + com.google.guava guava diff --git a/spring-boot-mybatis/mybatis-generator/README.md b/spring-boot-mybatis/mybatis-generator/README.md new file mode 100644 index 0000000..8ba1282 --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/README.md @@ -0,0 +1,6 @@ +How to generate: + +Set `generator.generate` to true + +Run `GeneratorApplication` + diff --git a/spring-boot-mybatis/mybatis-generator/pom.xml b/spring-boot-mybatis/mybatis-generator/pom.xml new file mode 100644 index 0000000..3837874 --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/pom.xml @@ -0,0 +1,95 @@ + + + 4.0.0 + + + alex + spring-boot-mybatis + 0.1.0-SNAPSHOT + ../pom.xml + + + mybatis-generator + 0.1.0-SNAPSHOT + jar + + + 2.2.224 + + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 3.0.3 + + + org.mybatis.generator + mybatis-generator-core + 1.4.2 + + + com.h2database + h2 + ${h2.version} + + + org.projectlombok + lombok + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.mybatis.spring.boot + mybatis-spring-boot-starter-test + 3.0.3 + test + + + + + + + src/main/resources + + + src/main/java + + **/*.java + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.4.2 + + ${project.basedir}/src/main/resources/generatorConfig.xml + true + true + + + + com.h2database + h2 + ${h2.version} + + + alex + mybatis-generator + 0.1.0-SNAPSHOT + + + + + + diff --git a/spring-boot-mybatis/mybatis-generator/src/main/java/alex/GeneratorApplication.java b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/GeneratorApplication.java new file mode 100644 index 0000000..449edcd --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/GeneratorApplication.java @@ -0,0 +1,51 @@ +package alex; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import lombok.extern.java.Log; +import org.mybatis.generator.api.MyBatisGenerator; +import org.mybatis.generator.api.VerboseProgressCallback; +import org.mybatis.generator.config.Configuration; +import org.mybatis.generator.config.xml.ConfigurationParser; +import org.mybatis.generator.internal.DefaultShellCallback; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.util.ResourceUtils; + +/** Created by qct on 2017/10/5. */ +@SpringBootApplication +@MapperScan("alex.dao") +@Log +public class GeneratorApplication implements CommandLineRunner { + + @Value("${generator.generate}") + boolean generate; + + public static void main(String[] args) { + SpringApplication.run(GeneratorApplication.class, args); + } + + @Override + public void run(String... args) throws Exception { + if (!generate) { + log.info("generator.generate is false, skip generator"); + return; + } + + List warnings = new ArrayList<>(); + boolean overwrite = true; + + File configFile = ResourceUtils.getFile("classpath:generatorConfig.xml"); + ConfigurationParser cp = new ConfigurationParser(warnings); + Configuration config = cp.parseConfiguration(configFile); + DefaultShellCallback callback = new DefaultShellCallback(overwrite); + MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); + myBatisGenerator.generate(new VerboseProgressCallback()); + + warnings.forEach(log::warning); + } +} diff --git a/spring-boot-mybatis/src/main/java/alex/dao/PersonExMapper.java b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/dao/PersonExMapper.java similarity index 100% rename from spring-boot-mybatis/src/main/java/alex/dao/PersonExMapper.java rename to spring-boot-mybatis/mybatis-generator/src/main/java/alex/dao/PersonExMapper.java diff --git a/spring-boot-mybatis/mybatis-generator/src/main/java/alex/dao/PersonMapper.java b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/dao/PersonMapper.java new file mode 100644 index 0000000..1709b04 --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/dao/PersonMapper.java @@ -0,0 +1,53 @@ +package alex.dao; + +import alex.dto.Person; + +public interface PersonMapper { + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table person + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + int deleteByPrimaryKey(Integer id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table person + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + int insert(Person row); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table person + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + int insertSelective(Person row); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table person + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + Person selectByPrimaryKey(Integer id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table person + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + int updateByPrimaryKeySelective(Person row); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table person + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + int updateByPrimaryKey(Person row); +} \ No newline at end of file diff --git a/spring-boot-mybatis/mybatis-generator/src/main/java/alex/dao/SchoolMapper.java b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/dao/SchoolMapper.java new file mode 100644 index 0000000..f4977ba --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/dao/SchoolMapper.java @@ -0,0 +1,53 @@ +package alex.dao; + +import alex.dto.School; + +public interface SchoolMapper { + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table school + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + int deleteByPrimaryKey(Integer id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table school + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + int insert(School row); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table school + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + int insertSelective(School row); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table school + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + School selectByPrimaryKey(Integer id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table school + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + int updateByPrimaryKeySelective(School row); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table school + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + int updateByPrimaryKey(School row); +} \ No newline at end of file diff --git a/spring-boot-mybatis/mybatis-generator/src/main/java/alex/dto/Person.java b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/dto/Person.java new file mode 100644 index 0000000..f0ff7f9 --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/dto/Person.java @@ -0,0 +1,48 @@ +package alex.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Person { + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column person.id + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + private Integer id; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column person.name + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + private String name; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column person.address + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + private String address; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column person.age + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + private Integer age; +} \ No newline at end of file diff --git a/spring-boot-mybatis/mybatis-generator/src/main/java/alex/dto/School.java b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/dto/School.java new file mode 100644 index 0000000..ecc05b0 --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/dto/School.java @@ -0,0 +1,30 @@ +package alex.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class School { + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column school.id + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + private Integer id; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column school.name + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + private String name; +} \ No newline at end of file diff --git a/spring-boot-mybatis/mybatis-generator/src/main/java/alex/plugin/DisableExamplePlugin.java b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/plugin/DisableExamplePlugin.java new file mode 100644 index 0000000..7b79ff6 --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/plugin/DisableExamplePlugin.java @@ -0,0 +1,172 @@ +package alex.plugin; + +import java.util.List; +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.PluginAdapter; +import org.mybatis.generator.api.dom.java.Interface; +import org.mybatis.generator.api.dom.java.Method; +import org.mybatis.generator.api.dom.java.TopLevelClass; +import org.mybatis.generator.api.dom.xml.XmlElement; + +/** + *

Created by qct on 2023/11/26. + */ +public class DisableExamplePlugin extends PluginAdapter { + + @Override + public boolean validate(List warnings) { + return true; + } + + @Override + public boolean clientCountByExampleMethodGenerated(Method method, Interface interfaze, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean clientDeleteByExampleMethodGenerated(Method method, Interface interfaze, + IntrospectedTable introspectedTable) { + return false; + + } + + @Override + public boolean clientSelectByExampleWithBLOBsMethodGenerated(Method method, Interface interfaze, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean clientSelectByExampleWithoutBLOBsMethodGenerated(Method method, Interface interfaze, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean clientUpdateByExampleSelectiveMethodGenerated(Method method, Interface interfaze, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean clientUpdateByExampleWithBLOBsMethodGenerated(Method method, Interface interfaze, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean clientUpdateByExampleWithoutBLOBsMethodGenerated(Method method, Interface interfaze, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean sqlMapCountByExampleElementGenerated(XmlElement element, IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean sqlMapDeleteByExampleElementGenerated(XmlElement element, IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean sqlMapExampleWhereClauseElementGenerated(XmlElement element, IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean sqlMapSelectByExampleWithoutBLOBsElementGenerated(XmlElement element, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean sqlMapSelectByExampleWithBLOBsElementGenerated(XmlElement element, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean sqlMapUpdateByExampleSelectiveElementGenerated(XmlElement element, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean sqlMapUpdateByExampleWithBLOBsElementGenerated(XmlElement element, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean sqlMapUpdateByExampleWithoutBLOBsElementGenerated(XmlElement element, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean providerCountByExampleMethodGenerated(Method method, TopLevelClass topLevelClass, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean providerDeleteByExampleMethodGenerated(Method method, TopLevelClass topLevelClass, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean providerSelectByExampleWithBLOBsMethodGenerated(Method method, TopLevelClass topLevelClass, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean providerSelectByExampleWithoutBLOBsMethodGenerated(Method method, TopLevelClass topLevelClass, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean providerUpdateByExampleSelectiveMethodGenerated(Method method, TopLevelClass topLevelClass, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean providerUpdateByExampleWithBLOBsMethodGenerated(Method method, TopLevelClass topLevelClass, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean providerUpdateByExampleWithoutBLOBsMethodGenerated(Method method, TopLevelClass topLevelClass, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean providerApplyWhereMethodGenerated(Method method, TopLevelClass topLevelClass, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean modelRecordWithBLOBsClassGenerated(TopLevelClass topLevelClass, + IntrospectedTable introspectedTable) { + return false; + } + + @Override + public boolean modelPrimaryKeyClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + return false; + } +} diff --git a/spring-boot-mybatis/mybatis-generator/src/main/java/alex/plugin/LombokPlugin.java b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/plugin/LombokPlugin.java new file mode 100644 index 0000000..c6e596e --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/plugin/LombokPlugin.java @@ -0,0 +1,57 @@ +package alex.plugin; + +import java.util.List; +import org.mybatis.generator.api.IntrospectedColumn; +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.PluginAdapter; +import org.mybatis.generator.api.dom.java.Method; +import org.mybatis.generator.api.dom.java.TopLevelClass; + +/** + *

Created by qct on 2023/11/26. + */ +public class LombokPlugin extends PluginAdapter { + + @Override + public boolean validate(List warnings) { + return true; + } + + @Override + public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + // @Data + topLevelClass.addImportedType("lombok.Data"); + topLevelClass.addAnnotation("@Data"); + + // @Builder + topLevelClass.addImportedType("lombok.Builder"); + topLevelClass.addAnnotation("@Builder"); + + // @NoArgsConstructor + topLevelClass.addImportedType("lombok.NoArgsConstructor"); + topLevelClass.addAnnotation("@NoArgsConstructor"); + + // @AllArgsConstructor + topLevelClass.addImportedType("lombok.AllArgsConstructor"); + topLevelClass.addAnnotation("@AllArgsConstructor"); + return super.modelBaseRecordClassGenerated(topLevelClass, introspectedTable); + } + + @Override + public boolean modelGetterMethodGenerated(Method method, + TopLevelClass topLevelClass, + IntrospectedColumn introspectedColumn, + IntrospectedTable introspectedTable, + ModelClassType modelClassType) { + return false; + } + + @Override + public boolean modelSetterMethodGenerated(Method method, + TopLevelClass topLevelClass, + IntrospectedColumn introspectedColumn, + IntrospectedTable introspectedTable, + ModelClassType modelClassType) { + return false; + } +} diff --git a/spring-boot-mybatis/mybatis-generator/src/main/java/alex/plugin/MapperPlusPlugin.java b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/plugin/MapperPlusPlugin.java new file mode 100644 index 0000000..514aadb --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/plugin/MapperPlusPlugin.java @@ -0,0 +1,330 @@ +package alex.plugin; + +import java.io.File; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import org.mybatis.generator.api.GeneratedJavaFile; +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.PluginAdapter; +import org.mybatis.generator.api.dom.DefaultJavaFormatter; +import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; +import org.mybatis.generator.api.dom.java.Interface; +import org.mybatis.generator.api.dom.java.JavaVisibility; +import org.mybatis.generator.api.dom.java.Method; +import org.mybatis.generator.api.dom.java.Parameter; +import org.mybatis.generator.api.dom.java.TypeParameter; +import org.mybatis.generator.api.dom.xml.Document; +import org.mybatis.generator.api.dom.xml.XmlElement; + +/** + *

Created by qct on 2023/11/26. + */ +public class MapperPlusPlugin extends PluginAdapter { + + private static final String BASE_PACKAGE_PROP = "base-mapper.target.package"; + + private static final String BASE_PROJECT_PROP = "base-mapper.target.project"; + + private static final String BASE_MAPPER_NAME_PROP = "base-mapper.name"; + + private static final String JAVA_MAPPER_PACKAGE_PROP = "java-mapper.target.package"; + + private static final String JAVA_MAPPER_PROJECT_PROP = "java-mapper.target.project"; + + private static final String JAVA_MAPPER_GENERATE_PROP = "java-mapper.generate"; + + private static final String JAVA_MAPPER_OVERRIDE_PROP = "java-mapper.override"; + + private static final String SELECT_ONE_BY_EXAMPLE_PROP = "select-one-by-example.disabled"; + + private List warnings; + + @Override + public boolean validate(List warnings) { + this.warnings = warnings; + return true; + } + + @Override + public void initialized(IntrospectedTable introspectedTable) { + String isGenerateJavaMapper = super.properties.getProperty(JAVA_MAPPER_GENERATE_PROP, "true"); + if (!Objects.equals(isGenerateJavaMapper, "true")) { + return; + } + overrideXmlFileName(introspectedTable); + overrideXmlNamespace(introspectedTable); + } + + @Override + public List contextGenerateAdditionalJavaFiles() { + String targetPackage = super.properties.getProperty(BASE_PACKAGE_PROP); + String mapperName = super.properties.getProperty(BASE_MAPPER_NAME_PROP, "BaseMapper"); + String interfaceName = targetPackage + "." + mapperName; + Interface baseMapperInterface = new Interface(new FullyQualifiedJavaType(interfaceName)); + + // BaseMapper + baseMapperInterface.addTypeParameter(new TypeParameter("T")); + baseMapperInterface.addTypeParameter(new TypeParameter("E")); + // count + addCountByExample(baseMapperInterface); + // delete + addDeleteByExample(baseMapperInterface); + addDeleteByPrimaryKey(baseMapperInterface); + // insert + addInsert(baseMapperInterface); + addInsertSelective(baseMapperInterface); + // select + addSelectByExample(baseMapperInterface); + addSelectOneByExample(baseMapperInterface); + addSelectByPrimaryKey(baseMapperInterface); + // update + addUpdateByExampleSelective(baseMapperInterface); + addUpdateByExample(baseMapperInterface); + addUpdateByPrimaryKeySelective(baseMapperInterface); + addUpdateByPrimaryKey(baseMapperInterface); + // import + baseMapperInterface.addImportedType( + new FullyQualifiedJavaType("org.apache.ibatis.annotations.Param")); + baseMapperInterface.addImportedType( + new FullyQualifiedJavaType("java.util.List")); + baseMapperInterface.setVisibility(JavaVisibility.PUBLIC); + + String targetProject = super.properties.getProperty(BASE_PROJECT_PROP); + GeneratedJavaFile baseMapperJavaFile = new GeneratedJavaFile( + baseMapperInterface, + targetProject, + new DefaultJavaFormatter() + ); + return Collections.singletonList(baseMapperJavaFile); + } + + protected void overrideXmlFileName(IntrospectedTable introspectedTable) { + String xmlMapperFileName = introspectedTable.getMyBatis3XmlMapperFileName(); + String newXmlMapperFileName = + xmlMapperFileName.replace("Mapper.xml", "GeneratedMapper.xml"); + introspectedTable.setMyBatis3XmlMapperFileName(newXmlMapperFileName); + } + + private void overrideXmlNamespace(IntrospectedTable introspectedTable) { + String javaMapperPackage = super.properties.getProperty(JAVA_MAPPER_PACKAGE_PROP); + String originalNamespace = introspectedTable.getMyBatis3SqlMapNamespace(); + int idx = originalNamespace.lastIndexOf("."); + String mapperInterfaceName = originalNamespace.substring(idx + 1); + String newNamespace = javaMapperPackage + "." + mapperInterfaceName; + introspectedTable.setMyBatis3JavaMapperType(newNamespace); + } + + private void addUpdateByPrimaryKey(Interface baseMapperInterface) { + // int updateByPrimaryKey(T row); + Method updateByPrimaryKey = new Method("updateByPrimaryKey"); + updateByPrimaryKey.setReturnType(new FullyQualifiedJavaType("int")); + updateByPrimaryKey.addParameter(new Parameter(new FullyQualifiedJavaType("T"), "row")); + updateByPrimaryKey.setAbstract(true); + baseMapperInterface.addMethod(updateByPrimaryKey); + } + + private void addUpdateByPrimaryKeySelective(Interface baseMapperInterface) { + // int updateByPrimaryKeySelective(T row); + Method updateByPrimaryKeySelective = new Method("updateByPrimaryKeySelective"); + updateByPrimaryKeySelective.setReturnType(new FullyQualifiedJavaType("int")); + updateByPrimaryKeySelective.addParameter( + new Parameter(new FullyQualifiedJavaType("T"), "row")); + updateByPrimaryKeySelective.setAbstract(true); + baseMapperInterface.addMethod(updateByPrimaryKeySelective); + } + + private void addSelectByPrimaryKey(Interface baseMapperInterface) { + // T selectByPrimaryKey(Long id); + Method selectByPrimaryKey = new Method("selectByPrimaryKey"); + selectByPrimaryKey.setReturnType(new FullyQualifiedJavaType("T")); + selectByPrimaryKey.addParameter( + new Parameter(new FullyQualifiedJavaType("Long"), "id")); + selectByPrimaryKey.setAbstract(true); + baseMapperInterface.addMethod(selectByPrimaryKey); + } + + private void addSelectByExample(Interface baseMapperInterface) { + // List selectByExample(E example); + Method selectByExample = new Method("selectByExample"); + selectByExample.setReturnType(new FullyQualifiedJavaType("List")); + selectByExample.addParameter(new Parameter(new FullyQualifiedJavaType("E"), "example")); + selectByExample.setAbstract(true); + baseMapperInterface.addMethod(selectByExample); + } + + private void addInsertSelective(Interface baseMapperInterface) { + // int insertSelective(T row); + Method insertSelective = new Method("insertSelective"); + insertSelective.setReturnType(new FullyQualifiedJavaType("int")); + insertSelective.addParameter(new Parameter(new FullyQualifiedJavaType("T"), "row")); + insertSelective.setAbstract(true); + baseMapperInterface.addMethod(insertSelective); + } + + private void addInsert(Interface baseMapperInterface) { + // int insert(T row); + Method insert = new Method("insert"); + insert.setReturnType(new FullyQualifiedJavaType("int")); + insert.addParameter(new Parameter(new FullyQualifiedJavaType("T"), "row")); + insert.setAbstract(true); + baseMapperInterface.addMethod(insert); + } + + private void addDeleteByPrimaryKey(Interface baseMapperInterface) { + // int deleteByPrimaryKey(Long id); + Method deleteByPrimaryKey = new Method("deleteByPrimaryKey"); + deleteByPrimaryKey.setReturnType(new FullyQualifiedJavaType("int")); + deleteByPrimaryKey.addParameter(new Parameter(new FullyQualifiedJavaType("Long"), "id")); + deleteByPrimaryKey.setAbstract(true); + baseMapperInterface.addMethod(deleteByPrimaryKey); + } + + private void addDeleteByExample(Interface baseMapperInterface) { + // int deleteByExample(E example); + Method deleteByExample = new Method("deleteByExample"); + deleteByExample.setReturnType(new FullyQualifiedJavaType("int")); + deleteByExample.addParameter(new Parameter(new FullyQualifiedJavaType("E"), "example")); + deleteByExample.setAbstract(true); + baseMapperInterface.addMethod(deleteByExample); + } + + private void addCountByExample(Interface baseMapperInterface) { + // long countByExample(E example); + Method countByExample = new Method("countByExample"); + countByExample.setReturnType(new FullyQualifiedJavaType("T")); + countByExample.addParameter(new Parameter(new FullyQualifiedJavaType("E"), "example")); + countByExample.setReturnType(new FullyQualifiedJavaType("long")); + countByExample.setAbstract(true); + baseMapperInterface.addMethod(countByExample); + } + + private void addSelectOneByExample(Interface baseMapperInterface) { + if ("false".equals(super.properties.getProperty(SELECT_ONE_BY_EXAMPLE_PROP, "false"))) { + Method selectOneByExample = new Method("selectOneByExample"); + baseMapperInterface.addImportedType(new FullyQualifiedJavaType("java.util.Optional")); + selectOneByExample.setReturnType(new FullyQualifiedJavaType("Optional")); + + Parameter exampleParam = new Parameter(new FullyQualifiedJavaType("E"), "example"); + selectOneByExample.addParameter(exampleParam); + + selectOneByExample.setAbstract(true); + baseMapperInterface.addMethod(selectOneByExample); + } else { + this.warnings.add("The 'selectOneByExample' method is not generated" + + " because the 'selectOneByExample' property is set to 'false'."); + } + } + + private void addUpdateByExampleSelective(Interface interfaze) { + // int updateByExampleSelective(@Param("row") T row, @Param("example") E example); + Method updateByExampleSelective = new Method("updateByExampleSelective"); + updateByExampleSelective.setReturnType(new FullyQualifiedJavaType("int")); + + Parameter rowParam = new Parameter(new FullyQualifiedJavaType("T"), "row"); + rowParam.addAnnotation("@Param(\"row\")"); + updateByExampleSelective.addParameter(rowParam); + + Parameter exampleParam = new Parameter(new FullyQualifiedJavaType("E"), "example"); + exampleParam.addAnnotation("@Param(\"example\")"); + updateByExampleSelective.addParameter(exampleParam); + + updateByExampleSelective.setAbstract(true); + interfaze.addMethod(updateByExampleSelective); + } + + private void addUpdateByExample(Interface interfaze) { + // int updateByExample(@Param("row") T row, @Param("example") E example); + Method updateByExample = new Method("updateByExample"); + updateByExample.setReturnType(new FullyQualifiedJavaType("int")); + + Parameter rowParam = new Parameter(new FullyQualifiedJavaType("T"), "row"); + updateByExample.addParameter(rowParam); + rowParam.addAnnotation("@Param(\"row\")"); + + Parameter exampleParam = new Parameter(new FullyQualifiedJavaType("E"), "example"); + exampleParam.addAnnotation("@Param(\"example\")"); + updateByExample.addParameter(exampleParam); + + updateByExample.setAbstract(true); + interfaze.addMethod(updateByExample); + } + + @Override + public boolean sqlMapDocumentGenerated(Document document, IntrospectedTable introspectedTable) { + // selectOneByExample + // if ("false".equals(super.properties.getProperty(SELECT_ONE_BY_EXAMPLE_PROP, "false"))) { + // XmlElement mapperParent = document.getRootElement(); + // SelectOneByExampleXmlElementGenerator generator = new SelectOneByExampleXmlElementGenerator(); + // generator.setContext(context); + // generator.setWarnings(warnings); + // generator.setIntrospectedTable(introspectedTable); + // generator.addElements(mapperParent); + // } + return true; + } + + @Override + public List contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) { + String isGenerateJavaMapper = super.properties.getProperty(JAVA_MAPPER_GENERATE_PROP, "true"); + if (!Objects.equals(isGenerateJavaMapper, "true")) { + return Collections.emptyList(); + } + + String javaMapperProject = super.properties.getProperty(JAVA_MAPPER_PROJECT_PROP); + String javaMapperPackage = super.properties.getProperty(JAVA_MAPPER_PACKAGE_PROP); + + String xmlNamespace = introspectedTable.getMyBatis3SqlMapNamespace(); + int idx = xmlNamespace.lastIndexOf("."); + String interfaceName = xmlNamespace.substring(idx + 1); + + boolean allowOverride = + Boolean.parseBoolean(super.properties.getProperty(JAVA_MAPPER_OVERRIDE_PROP, "false")); + if (javaMapperExists(javaMapperProject, javaMapperPackage, interfaceName)) { + if (!allowOverride) { + return Collections.emptyList(); + } + warnings.add("java mapper interface " + + interfaceName + + " already exists in " + + javaMapperProject + + " and will be overridden."); + } + + String fullInterfaceName = javaMapperPackage + "." + interfaceName; + Interface baseMapperInterface = new Interface(new FullyQualifiedJavaType(fullInterfaceName)); + baseMapperInterface.setVisibility(JavaVisibility.PUBLIC); + + // import BaseMapper + String baseMapperPackage = super.properties.getProperty(BASE_PACKAGE_PROP); + String baseMapperName = super.properties.getProperty(BASE_MAPPER_NAME_PROP, "BaseMapper"); + baseMapperInterface.addImportedType( + new FullyQualifiedJavaType(baseMapperPackage + "." + baseMapperName)); + + // extends BaseMapper + String baseRecordType = introspectedTable.getBaseRecordType(); + String exampleType = introspectedTable.getExampleType(); + baseMapperInterface.addImportedType(new FullyQualifiedJavaType(baseRecordType)); + baseMapperInterface.addImportedType(new FullyQualifiedJavaType(exampleType)); + + String simplePojoType = baseRecordType.substring(baseRecordType.lastIndexOf(".") + 1); + String simpleExampleType = exampleType.substring(exampleType.lastIndexOf(".") + 1); + baseMapperInterface.addSuperInterface(new FullyQualifiedJavaType( + baseMapperName + "<" + simplePojoType + "," + simpleExampleType + ">")); + + GeneratedJavaFile baseMapperJavaFile = new GeneratedJavaFile( + baseMapperInterface, + javaMapperProject, + new DefaultJavaFormatter() + ); + return Collections.singletonList(baseMapperJavaFile); + } + + private boolean javaMapperExists(String mapperProject, String mapperPackage, String mapperName) { + String mapperPackagePath = mapperPackage.replace(".", File.separator); + String fileName = mapperProject + File.separator + + mapperPackagePath + File.separator + + mapperName + ".java"; + return new File(fileName).exists(); + } +} \ No newline at end of file diff --git a/spring-boot-mybatis/mybatis-generator/src/main/java/alex/plugin/NullSafePlugin.java b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/plugin/NullSafePlugin.java new file mode 100644 index 0000000..56caaa2 --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/plugin/NullSafePlugin.java @@ -0,0 +1,173 @@ +package alex.plugin; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.mybatis.generator.api.IntrospectedColumn; +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.PluginAdapter; +import org.mybatis.generator.api.dom.java.Field; +import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; +import org.mybatis.generator.api.dom.java.Method; +import org.mybatis.generator.api.dom.java.Parameter; +import org.mybatis.generator.api.dom.java.TopLevelClass; + +/** + *

Created by qct on 2023/11/26. + */ +public class NullSafePlugin extends PluginAdapter { + + private static final String IGNORE_COLUMN_PROP = "ignore.columns"; + + private static final String ADD_SPRING_NULLABLE_ANNOTATION = "spring.nullable"; + + private static final String ADD_OPTIONAL_GETTER = "optional.getter"; + + private static final String ALL = "*"; + + private Map> ignoredTableColumns = new HashMap<>(); + + private boolean addSpringNullableAnnotation; + + private boolean addOptionalGetter; + + @Override + public boolean validate(List warnings) { + return true; + } + + @Override + public void initialized(IntrospectedTable introspectedTable) { + addSpringNullableAnnotation = Boolean.parseBoolean( + properties.getOrDefault(ADD_SPRING_NULLABLE_ANNOTATION, "false").toString()); + addOptionalGetter = Boolean.parseBoolean( + properties.getOrDefault(ADD_OPTIONAL_GETTER, "true").toString()); + String ignoreColumns = (String) super.properties.getOrDefault(IGNORE_COLUMN_PROP, ""); + if (ignoreColumns.isEmpty()) { + return; + } + + String[] ignoreColumnsArray = ignoreColumns.split(","); + for (String ignoreColumnPattern : ignoreColumnsArray) { + int separatorIndex = ignoreColumnPattern.lastIndexOf("."); + if (separatorIndex == -1) { + continue; + } + + String tableName = ignoreColumnPattern.substring(0, separatorIndex).trim(); + String columnName = ignoreColumnPattern.substring(separatorIndex + 1).trim(); + Set values = ignoredTableColumns.computeIfAbsent(tableName, k -> new HashSet<>()); + values.add(columnName); + } + } + + @Override + public boolean modelFieldGenerated(Field field, + TopLevelClass topLevelClass, + IntrospectedColumn introspectedColumn, + IntrospectedTable introspectedTable, + ModelClassType modelClassType) { + if (ignore(introspectedTable.getFullyQualifiedTable().getIntrospectedTableName(), + introspectedColumn.getActualColumnName())) { + return true; + } + + addSpringNullableAnnotation(field, topLevelClass, introspectedColumn); + return true; + } + + @Override + public boolean modelGetterMethodGenerated(Method method, + TopLevelClass topLevelClass, + IntrospectedColumn introspectedColumn, + IntrospectedTable introspectedTable, + ModelClassType modelClassType) { + if (ignore(introspectedTable.getFullyQualifiedTable().getIntrospectedTableName(), + introspectedColumn.getActualColumnName())) { + return true; + } + + addOptionalGetter(method, topLevelClass, introspectedColumn); + addSpringNullableAnnotation(method, topLevelClass, introspectedColumn); + return true; + } + + @Override + public boolean modelSetterMethodGenerated(Method method, + TopLevelClass topLevelClass, + IntrospectedColumn introspectedColumn, + IntrospectedTable introspectedTable, + ModelClassType modelClassType) { + if (ignore(introspectedTable.getFullyQualifiedTable().getIntrospectedTableName(), + introspectedColumn.getActualColumnName())) { + return true; + } + + Parameter parameter = method.getParameters().iterator().next(); + addSpringNullableAnnotation(parameter, topLevelClass, introspectedColumn); + return true; + } + + protected boolean ignore(String tableName, String columnName) { + if (ignoredTableColumns.containsKey(tableName)) { + Set ignoredColumns = ignoredTableColumns.get(tableName); + if (ignoredColumns.contains(columnName)) { + return true; + } + } + + if (ignoredTableColumns.containsKey(ALL)) { + Set ignoredColumns = ignoredTableColumns.get(ALL); + if (ignoredColumns.contains(columnName)) { + return true; + } + } + return false; + } + + private void addOptionalGetter(Method method, + TopLevelClass topLevelClass, + IntrospectedColumn introspectedColumn) { + if (addOptionalGetter && introspectedColumn.isNullable()) { + method.getReturnType().ifPresent(returnType -> { + topLevelClass.addImportedType(new FullyQualifiedJavaType("java.util.Optional")); + Method optionGetter = new Method(method.getName() + "Optional"); + optionGetter.setVisibility(method.getVisibility()); + String shortName = returnType.getShortName(); + optionGetter.setReturnType( + new FullyQualifiedJavaType("java.util.Optional<" + shortName + ">")); + optionGetter.addBodyLine("return Optional.ofNullable(" + introspectedColumn.getJavaProperty() + ");"); + topLevelClass.addMethod(optionGetter); + }); + } + } + + private void addSpringNullableAnnotation(Method method, + TopLevelClass topLevelClass, + IntrospectedColumn introspectedColumn) { + if (addSpringNullableAnnotation && introspectedColumn.isNullable()) { + topLevelClass.addImportedType("org.springframework.lang.Nullable"); + method.addAnnotation("@Nullable"); + } + } + + private void addSpringNullableAnnotation(Field field, + TopLevelClass topLevelClass, + IntrospectedColumn introspectedColumn) { + if (addSpringNullableAnnotation && introspectedColumn.isNullable()) { + topLevelClass.addImportedType("org.springframework.lang.Nullable"); + field.addAnnotation("@Nullable"); + } + } + + private void addSpringNullableAnnotation(Parameter parameter, + TopLevelClass topLevelClass, + IntrospectedColumn introspectedColumn) { + if (addSpringNullableAnnotation && introspectedColumn.isNullable()) { + topLevelClass.addImportedType("org.springframework.lang.Nullable"); + parameter.addAnnotation("@Nullable"); + } + } +} \ No newline at end of file diff --git a/spring-boot-mybatis/mybatis-generator/src/main/java/alex/plugin/OptionalPlugin.java b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/plugin/OptionalPlugin.java new file mode 100644 index 0000000..cba3233 --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/src/main/java/alex/plugin/OptionalPlugin.java @@ -0,0 +1,49 @@ +package alex.plugin; + +import java.util.List; +import java.util.Optional; +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.PluginAdapter; +import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; +import org.mybatis.generator.api.dom.java.Interface; +import org.mybatis.generator.api.dom.java.Method; +import org.mybatis.generator.api.dom.java.TopLevelClass; + +/** + *

Created by qct on 2023/11/26. + */ +public class OptionalPlugin extends PluginAdapter { + + @Override + public boolean validate(List warnings) { + return true; + } + + @Override + public boolean clientBasicSelectOneMethodGenerated(Method method, Interface interfaze, + IntrospectedTable introspectedTable) { + method.getReturnType().ifPresent(returnType -> { + FullyQualifiedJavaType type = new FullyQualifiedJavaType(Optional.class.getName()); + type.addTypeArgument(returnType); + method.setReturnType(type); + }); + return true; + } + + @Override + public boolean clientSelectByPrimaryKeyMethodGenerated(Method method, Interface interfaze, + IntrospectedTable introspectedTable) { + method.getReturnType().ifPresent(returnType -> { + FullyQualifiedJavaType type = new FullyQualifiedJavaType(Optional.class.getName()); + type.addTypeArgument(returnType); + method.setReturnType(type); + }); + return true; + } + + @Override + public boolean modelRecordWithBLOBsClassGenerated(TopLevelClass topLevelClass, + IntrospectedTable introspectedTable) { + return false; + } +} diff --git a/spring-boot-mybatis/mybatis-generator/src/main/resources/application.yml b/spring-boot-mybatis/mybatis-generator/src/main/resources/application.yml new file mode 100644 index 0000000..af2fc9b --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/src/main/resources/application.yml @@ -0,0 +1,28 @@ +mybatis: + type-aliases-package: alex.dto + mapper-locations: classpath:mapper/*.xml +spring: + datasource: + driver-class-name: org.h2.Driver + url: jdbc:h2:mem:testdb;MODE=MySQL;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE;DB_CLOSE_DELAY=-1 + username: sa + password: sa + sql: + init: + mode: always + schema-locations: classpath:sql/schema-h2.sql + data-locations: classpath:sql/data-h2.sql + username: sa + password: sa + main: + banner-mode: off + h2: + console: + enabled: false + +generator: + generate: false + +logging: + level: + org.mybatis.generator: trace diff --git a/spring-boot-mybatis/mybatis-generator/src/main/resources/generatorConfig.properties b/spring-boot-mybatis/mybatis-generator/src/main/resources/generatorConfig.properties new file mode 100644 index 0000000..7521459 --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/src/main/resources/generatorConfig.properties @@ -0,0 +1,11 @@ +jdbc.driver=org.h2.Driver +jdbc.url=jdbc:h2:mem:testdb;MODE=MySQL;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE; +jdbc.user=sa +jdbc.password=sa +model.target.package=alex.dto +model.target.project=./spring-boot-mybatis/generator +dao.target.package=alex.dao +dao.target.project=./spring-boot-mybatis/generator +mapper.target.package=mapper +mapper.target.project=./spring-boot-mybatis/generator + diff --git a/spring-boot-mybatis/src/main/resources/generatorConfig.xml b/spring-boot-mybatis/mybatis-generator/src/main/resources/generatorConfig.xml similarity index 76% rename from spring-boot-mybatis/src/main/resources/generatorConfig.xml rename to spring-boot-mybatis/mybatis-generator/src/main/resources/generatorConfig.xml index 934211d..8022d52 100644 --- a/spring-boot-mybatis/src/main/resources/generatorConfig.xml +++ b/spring-boot-mybatis/mybatis-generator/src/main/resources/generatorConfig.xml @@ -7,9 +7,10 @@ - - - + + + + @@ -24,8 +25,7 @@ - + @@ -34,18 +34,18 @@ + targetProject="${mapper.target.project}/src/main/resources"/> - - - +
+
- - +
+
\ No newline at end of file diff --git a/spring-boot-mybatis/src/main/resources/alex/dao/PersonExMapper.xml b/spring-boot-mybatis/mybatis-generator/src/main/resources/mapper/PersonExMapper.xml similarity index 74% rename from spring-boot-mybatis/src/main/resources/alex/dao/PersonExMapper.xml rename to spring-boot-mybatis/mybatis-generator/src/main/resources/mapper/PersonExMapper.xml index 1792768..6007658 100644 --- a/spring-boot-mybatis/src/main/resources/alex/dao/PersonExMapper.xml +++ b/spring-boot-mybatis/mybatis-generator/src/main/resources/mapper/PersonExMapper.xml @@ -2,11 +2,6 @@ - diff --git a/spring-boot-mybatis/mybatis-generator/src/main/resources/mapper/PersonMapper.xml b/spring-boot-mybatis/mybatis-generator/src/main/resources/mapper/PersonMapper.xml new file mode 100644 index 0000000..fef8bca --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/src/main/resources/mapper/PersonMapper.xml @@ -0,0 +1,116 @@ + + + + + + + + + + + + + id, name, address, age + + + + + delete from person + where id = #{id,jdbcType=INTEGER} + + + + insert into person (name, address, age + ) + values (#{name,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER} + ) + + + + insert into person + + + name, + + + address, + + + age, + + + + + #{name,jdbcType=VARCHAR}, + + + #{address,jdbcType=VARCHAR}, + + + #{age,jdbcType=INTEGER}, + + + + + + update person + + + name = #{name,jdbcType=VARCHAR}, + + + address = #{address,jdbcType=VARCHAR}, + + + age = #{age,jdbcType=INTEGER}, + + + where id = #{id,jdbcType=INTEGER} + + + + update person + set name = #{name,jdbcType=VARCHAR}, + address = #{address,jdbcType=VARCHAR}, + age = #{age,jdbcType=INTEGER} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/spring-boot-mybatis/mybatis-generator/src/main/resources/mapper/SchoolMapper.xml b/spring-boot-mybatis/mybatis-generator/src/main/resources/mapper/SchoolMapper.xml new file mode 100644 index 0000000..848c9a1 --- /dev/null +++ b/spring-boot-mybatis/mybatis-generator/src/main/resources/mapper/SchoolMapper.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + id, name + + + + + delete from school + where id = #{id,jdbcType=INTEGER} + + + + insert into school (name) + values (#{name,jdbcType=VARCHAR}) + + + + insert into school + + + name, + + + + + #{name,jdbcType=VARCHAR}, + + + + + + update school + + + name = #{name,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=INTEGER} + + + + update school + set name = #{name,jdbcType=VARCHAR} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/spring-boot-mybatis/src/test/resources/sql/data-h2.sql b/spring-boot-mybatis/mybatis-generator/src/main/resources/sql/data-h2.sql similarity index 100% rename from spring-boot-mybatis/src/test/resources/sql/data-h2.sql rename to spring-boot-mybatis/mybatis-generator/src/main/resources/sql/data-h2.sql diff --git a/spring-boot-mybatis/src/test/resources/sql/schema-h2.sql b/spring-boot-mybatis/mybatis-generator/src/main/resources/sql/schema-h2.sql similarity index 100% rename from spring-boot-mybatis/src/test/resources/sql/schema-h2.sql rename to spring-boot-mybatis/mybatis-generator/src/main/resources/sql/schema-h2.sql diff --git a/spring-boot-mybatis/src/test/java/alex/dao/PersonExMapperTest.java b/spring-boot-mybatis/mybatis-generator/src/test/java/alex/dao/PersonExMapperTest.java similarity index 81% rename from spring-boot-mybatis/src/test/java/alex/dao/PersonExMapperTest.java rename to spring-boot-mybatis/mybatis-generator/src/test/java/alex/dao/PersonExMapperTest.java index 25255e6..45ca10e 100644 --- a/spring-boot-mybatis/src/test/java/alex/dao/PersonExMapperTest.java +++ b/spring-boot-mybatis/mybatis-generator/src/test/java/alex/dao/PersonExMapperTest.java @@ -1,10 +1,12 @@ package alex.dao; import java.util.List; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mybatis.spring.boot.test.autoconfigure.MybatisTest; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.annotation.Rollback; import org.springframework.test.context.junit.jupiter.SpringExtension; /** Created by qct on 2017/10/5. */ @@ -18,6 +20,7 @@ public class PersonExMapperTest { @Test public void queryIds() throws Exception { List ids = exMapper.queryIds(); - System.out.println(ids.size()); + + Assertions.assertEquals(1, ids.size()); } } diff --git a/spring-boot-mybatis/src/test/java/alex/dao/PersonMapperTest.java b/spring-boot-mybatis/mybatis-generator/src/test/java/alex/dao/PersonMapperTest.java similarity index 66% rename from spring-boot-mybatis/src/test/java/alex/dao/PersonMapperTest.java rename to spring-boot-mybatis/mybatis-generator/src/test/java/alex/dao/PersonMapperTest.java index 28cd518..e85fb22 100644 --- a/spring-boot-mybatis/src/test/java/alex/dao/PersonMapperTest.java +++ b/spring-boot-mybatis/mybatis-generator/src/test/java/alex/dao/PersonMapperTest.java @@ -1,8 +1,8 @@ package alex.dao; import alex.dto.Person; -import alex.dto.PersonExample; import java.util.List; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mybatis.spring.boot.test.autoconfigure.MybatisTest; @@ -17,16 +17,14 @@ public class PersonMapperTest { @Autowired private PersonMapper mapper; - @Test - public void selectByExample() throws Exception { - List people = mapper.selectByExample(new PersonExample()); - System.out.println(people.size()); - } + @Autowired + private PersonExMapper exMapper; @Test public void selectByPrimaryKey() throws Exception { - Person person = mapper.selectByPrimaryKey(5); - System.out.println(person); + Person person = mapper.selectByPrimaryKey(1); + + Assertions.assertEquals(1, person.getId()); } @Test @@ -38,5 +36,13 @@ public void insertSelective() throws Exception { p.setAge(22 + i); mapper.insertSelective(p); } + + List ids = exMapper.queryIds(); + Assertions.assertEquals(11, ids.size()); + + for (Integer id : ids) { + Person p = mapper.selectByPrimaryKey(id); + Assertions.assertNotNull(p); + } } } diff --git a/spring-boot-mybatis/mybatis-plus/pom.xml b/spring-boot-mybatis/mybatis-plus/pom.xml new file mode 100644 index 0000000..ac468a1 --- /dev/null +++ b/spring-boot-mybatis/mybatis-plus/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + + alex + spring-boot-mybatis + 0.1.0-SNAPSHOT + ../pom.xml + + + mybatis-plus + 0.1.0-SNAPSHOT + jar + + + + com.baomidou + mybatis-plus-boot-starter + 3.5.4.1 + + + com.h2database + h2 + 2.2.224 + runtime + + + org.projectlombok + lombok + + + + org.springframework.boot + spring-boot-starter-test + test + + + com.baomidou + mybatis-plus-boot-starter-test + 3.5.4.1 + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/spring-boot-mybatis/src/main/java/alex/Application.java b/spring-boot-mybatis/mybatis-plus/src/main/java/alex/mybatis/plus/MybatisPlusApplication.java similarity index 62% rename from spring-boot-mybatis/src/main/java/alex/Application.java rename to spring-boot-mybatis/mybatis-plus/src/main/java/alex/mybatis/plus/MybatisPlusApplication.java index eb0515c..588b2b6 100644 --- a/spring-boot-mybatis/src/main/java/alex/Application.java +++ b/spring-boot-mybatis/mybatis-plus/src/main/java/alex/mybatis/plus/MybatisPlusApplication.java @@ -1,4 +1,4 @@ -package alex; +package alex.mybatis.plus; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; @@ -6,10 +6,10 @@ /** Created by qct on 2017/10/5. */ @SpringBootApplication -@MapperScan("alex.dao") -public class Application { +@MapperScan("alex.mybatis.plus.mapper") +public class MybatisPlusApplication { public static void main(String[] args) { - SpringApplication.run(Application.class, args); + SpringApplication.run(MybatisPlusApplication.class, args); } } diff --git a/spring-boot-mybatis/mybatis-plus/src/main/java/alex/mybatis/plus/dto/Person.java b/spring-boot-mybatis/mybatis-plus/src/main/java/alex/mybatis/plus/dto/Person.java new file mode 100644 index 0000000..04707df --- /dev/null +++ b/spring-boot-mybatis/mybatis-plus/src/main/java/alex/mybatis/plus/dto/Person.java @@ -0,0 +1,44 @@ +package alex.mybatis.plus.dto; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("`person`") +public class Person { + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column person.id + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + private Integer id; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column person.name + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + private String name; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column person.address + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + private String address; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column person.age + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + private Integer age; +} \ No newline at end of file diff --git a/spring-boot-mybatis/mybatis-plus/src/main/java/alex/mybatis/plus/dto/School.java b/spring-boot-mybatis/mybatis-plus/src/main/java/alex/mybatis/plus/dto/School.java new file mode 100644 index 0000000..dfef730 --- /dev/null +++ b/spring-boot-mybatis/mybatis-plus/src/main/java/alex/mybatis/plus/dto/School.java @@ -0,0 +1,26 @@ +package alex.mybatis.plus.dto; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("`school`") +public class School { + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column school.id + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + private Integer id; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column school.name + * + * @mbg.generated Mon Nov 27 23:50:17 GST 2023 + */ + private String name; +} \ No newline at end of file diff --git a/spring-boot-mybatis/mybatis-plus/src/main/java/alex/mybatis/plus/mapper/PersonMapper.java b/spring-boot-mybatis/mybatis-plus/src/main/java/alex/mybatis/plus/mapper/PersonMapper.java new file mode 100644 index 0000000..8ef9cf0 --- /dev/null +++ b/spring-boot-mybatis/mybatis-plus/src/main/java/alex/mybatis/plus/mapper/PersonMapper.java @@ -0,0 +1,11 @@ +package alex.mybatis.plus.mapper; + +import alex.mybatis.plus.dto.Person; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

Created by qct on 2023/11/28. + */ +public interface PersonMapper extends BaseMapper { + +} diff --git a/spring-boot-mybatis/mybatis-plus/src/main/java/alex/mybatis/plus/mapper/SchoolMapper.java b/spring-boot-mybatis/mybatis-plus/src/main/java/alex/mybatis/plus/mapper/SchoolMapper.java new file mode 100644 index 0000000..3d19d53 --- /dev/null +++ b/spring-boot-mybatis/mybatis-plus/src/main/java/alex/mybatis/plus/mapper/SchoolMapper.java @@ -0,0 +1,11 @@ +package alex.mybatis.plus.mapper; + +import alex.mybatis.plus.dto.School; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

Created by qct on 2023/11/28. + */ +public interface SchoolMapper extends BaseMapper { + +} diff --git a/spring-boot-mybatis/src/test/resources/application.yml b/spring-boot-mybatis/mybatis-plus/src/main/resources/application.yml similarity index 66% rename from spring-boot-mybatis/src/test/resources/application.yml rename to spring-boot-mybatis/mybatis-plus/src/main/resources/application.yml index 661a556..4ef8ee6 100644 --- a/spring-boot-mybatis/src/test/resources/application.yml +++ b/spring-boot-mybatis/mybatis-plus/src/main/resources/application.yml @@ -1,12 +1,15 @@ spring: datasource: - url: jdbc:h2:mem:testdb;MODE=MySQL;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE; + driver-class-name: org.h2.Driver + url: jdbc:h2:mem:testdb;MODE=MySQL;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE;DB_CLOSE_DELAY=-1 username: sa password: sa - driver-class-name: org.h2.Driver sql: init: + mode: always schema-locations: classpath:sql/schema-h2.sql data-locations: classpath:sql/data-h2.sql -mybatis: - mapper-locations: classpath:mapper/*.xml \ No newline at end of file + username: sa + password: sa + main: + banner-mode: off diff --git a/spring-boot-mybatis/mybatis-plus/src/main/resources/sql/data-h2.sql b/spring-boot-mybatis/mybatis-plus/src/main/resources/sql/data-h2.sql new file mode 100644 index 0000000..a52ddc2 --- /dev/null +++ b/spring-boot-mybatis/mybatis-plus/src/main/resources/sql/data-h2.sql @@ -0,0 +1 @@ +insert into person (name, address, age) values ('zhangsan', 'beijing', 20); \ No newline at end of file diff --git a/spring-boot-mybatis/mybatis-plus/src/main/resources/sql/schema-h2.sql b/spring-boot-mybatis/mybatis-plus/src/main/resources/sql/schema-h2.sql new file mode 100644 index 0000000..e8b0173 --- /dev/null +++ b/spring-boot-mybatis/mybatis-plus/src/main/resources/sql/schema-h2.sql @@ -0,0 +1,15 @@ +drop table if exists person; +create table person +( + id int auto_increment primary key, + name varchar(20) null, + address varchar(20) null, + age int null +); + +drop table if exists school; +create table school +( + id int auto_increment primary key, + name varchar(20) null +); \ No newline at end of file diff --git a/spring-boot-mybatis/mybatis-plus/src/test/java/alex/mybatis/plus/mapper/PersonMapperTest.java b/spring-boot-mybatis/mybatis-plus/src/test/java/alex/mybatis/plus/mapper/PersonMapperTest.java new file mode 100644 index 0000000..2926e31 --- /dev/null +++ b/spring-boot-mybatis/mybatis-plus/src/test/java/alex/mybatis/plus/mapper/PersonMapperTest.java @@ -0,0 +1,34 @@ +package alex.mybatis.plus.mapper; + +import alex.mybatis.plus.dto.Person; +import com.baomidou.mybatisplus.test.autoconfigure.MybatisPlusTest; +import java.util.List; +import lombok.extern.java.Log; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +/** + *

Created by qct on 2023/11/28. + */ +@ExtendWith(SpringExtension.class) +@MybatisPlusTest +@Log +public class PersonMapperTest { + + @Autowired + private PersonMapper personMapper; + + @Test + public void testSelect() { + log.info("----- selectAll method test ------"); + List people = personMapper.selectList(null); + + Assertions.assertEquals(1, people.size()); + people.forEach(p -> log.info(p.toString())); + + } + +} \ No newline at end of file diff --git a/spring-boot-mybatis/pom.xml b/spring-boot-mybatis/pom.xml index dd7bb3d..cb42bf9 100644 --- a/spring-boot-mybatis/pom.xml +++ b/spring-boot-mybatis/pom.xml @@ -11,74 +11,11 @@ spring-boot-mybatis 0.1.0-SNAPSHOT - jar + pom - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - 3.0.3 - - - com.mysql - mysql-connector-j - - - org.mybatis.generator - mybatis-generator-core - 1.4.2 - - - org.springframework.boot - spring-boot-starter-test - test - - - org.mybatis.spring.boot - mybatis-spring-boot-starter-test - 3.0.3 - test - - - com.h2database - h2 - 2.2.224 - test - - - + + mybatis-generator + mybatis-plus + - - - - org.springframework.boot - spring-boot-maven-plugin - - exec - - - - org.mybatis.generator - mybatis-generator-maven-plugin - 1.4.2 - - src/main/resources/generatorConfig.xml - true - true - - - - com.mysql - mysql-connector-j - ${mysql.version} - - - alex - spring-boot-mybatis - 0.1.0-SNAPSHOT - - - - - diff --git a/spring-boot-mybatis/src/main/java/alex/BaseMapper.java b/spring-boot-mybatis/src/main/java/alex/BaseMapper.java deleted file mode 100644 index 807c8c9..0000000 --- a/spring-boot-mybatis/src/main/java/alex/BaseMapper.java +++ /dev/null @@ -1,31 +0,0 @@ -package alex; - -import java.io.Serializable; -import java.util.List; -import org.apache.ibatis.annotations.Param; - -/** Created by qct on 2017/10/5. */ -public interface BaseMapper { - - long countByExample(E example); - - int deleteByExample(E example); - - int deleteByPrimaryKey(PK pk); - - int insert(T record); - - int insertSelective(T record); - - List selectByExample(E example); - - T selectByPrimaryKey(PK pk); - - int updateByExampleSelective(@Param("record") T record, @Param("example") E example); - - int updateByExample(@Param("record") T record, @Param("example") E example); - - int updateByPrimaryKeySelective(T record); - - int updateByPrimaryKey(T record); -} diff --git a/spring-boot-mybatis/src/main/java/alex/BaseMapperGeneratorPlugin.java b/spring-boot-mybatis/src/main/java/alex/BaseMapperGeneratorPlugin.java deleted file mode 100644 index 9f0838c..0000000 --- a/spring-boot-mybatis/src/main/java/alex/BaseMapperGeneratorPlugin.java +++ /dev/null @@ -1,39 +0,0 @@ -package alex; - -import java.util.List; -import org.mybatis.generator.api.IntrospectedTable; -import org.mybatis.generator.api.PluginAdapter; -import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; -import org.mybatis.generator.api.dom.java.Interface; - -/** Created by qct on 2017/10/5. */ -public class BaseMapperGeneratorPlugin extends PluginAdapter { - - @Override - public boolean clientGenerated(Interface interfaze, IntrospectedTable introspectedTable) { - // 主键默认采用java.lang.Integer - FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType("BaseMapper<" - + introspectedTable.getBaseRecordType() - + "," - + introspectedTable.getExampleType() - + ",java.lang.Integer" - + ">"); - FullyQualifiedJavaType imp = new FullyQualifiedJavaType("alex.BaseMapper"); - - // 添加 extends MybatisBaseMapper - interfaze.addSuperInterface(fqjt); - - // 添加import my.mabatis.example.base.MybatisBaseMapper; - interfaze.addImportedType(imp); - - // 方法不需要 - interfaze.getMethods().clear(); - interfaze.getAnnotations().clear(); - return true; - } - - @Override - public boolean validate(List warnings) { - return true; - } -} diff --git a/spring-boot-mybatis/src/main/java/alex/dao/PersonMapper.java b/spring-boot-mybatis/src/main/java/alex/dao/PersonMapper.java deleted file mode 100644 index d00047b..0000000 --- a/spring-boot-mybatis/src/main/java/alex/dao/PersonMapper.java +++ /dev/null @@ -1,7 +0,0 @@ -package alex.dao; - -import alex.BaseMapper; -import alex.dto.Person; -import alex.dto.PersonExample; - -public interface PersonMapper extends BaseMapper {} diff --git a/spring-boot-mybatis/src/main/java/alex/dao/SchoolMapper.java b/spring-boot-mybatis/src/main/java/alex/dao/SchoolMapper.java deleted file mode 100644 index 41e0ad6..0000000 --- a/spring-boot-mybatis/src/main/java/alex/dao/SchoolMapper.java +++ /dev/null @@ -1,7 +0,0 @@ -package alex.dao; - -import alex.BaseMapper; -import alex.dto.School; -import alex.dto.SchoolExample; - -public interface SchoolMapper extends BaseMapper {} diff --git a/spring-boot-mybatis/src/main/java/alex/dto/Person.java b/spring-boot-mybatis/src/main/java/alex/dto/Person.java deleted file mode 100644 index c040bf7..0000000 --- a/spring-boot-mybatis/src/main/java/alex/dto/Person.java +++ /dev/null @@ -1,188 +0,0 @@ -package alex.dto; - -public class Person { - - /** - * This field was generated by MyBatis Generator. This field corresponds to the database column - * person.id - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - private Integer id; - - /** - * This field was generated by MyBatis Generator. This field corresponds to the database column - * person.name - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - private String name; - - /** - * This field was generated by MyBatis Generator. This field corresponds to the database column - * person.address - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - private String address; - - /** - * This field was generated by MyBatis Generator. This field corresponds to the database column - * person.age - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - private Integer age; - - /** - * This method was generated by MyBatis Generator. This method returns the value of the database - * column person.id - * - * @return the value of person.id - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public Integer getId() { - return id; - } - - /** - * This method was generated by MyBatis Generator. This method sets the value of the database - * column person.id - * - * @param id the value for person.id - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public void setId(Integer id) { - this.id = id; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public Person withId(Integer id) { - this.setId(id); - return this; - } - - /** - * This method was generated by MyBatis Generator. This method returns the value of the database - * column person.name - * - * @return the value of person.name - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public String getName() { - return name; - } - - /** - * This method was generated by MyBatis Generator. This method sets the value of the database - * column person.name - * - * @param name the value for person.name - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public void setName(String name) { - this.name = name == null ? null : name.trim(); - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public Person withName(String name) { - this.setName(name); - return this; - } - - /** - * This method was generated by MyBatis Generator. This method returns the value of the database - * column person.address - * - * @return the value of person.address - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public String getAddress() { - return address; - } - - /** - * This method was generated by MyBatis Generator. This method sets the value of the database - * column person.address - * - * @param address the value for person.address - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public void setAddress(String address) { - this.address = address == null ? null : address.trim(); - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public Person withAddress(String address) { - this.setAddress(address); - return this; - } - - /** - * This method was generated by MyBatis Generator. This method returns the value of the database - * column person.age - * - * @return the value of person.age - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public Integer getAge() { - return age; - } - - /** - * This method was generated by MyBatis Generator. This method sets the value of the database - * column person.age - * - * @param age the value for person.age - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public void setAge(Integer age) { - this.age = age; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public Person withAge(Integer age) { - this.setAge(age); - return this; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(getClass().getSimpleName()); - sb.append(" ["); - sb.append("Hash = ").append(hashCode()); - sb.append(", id=").append(id); - sb.append(", name=").append(name); - sb.append(", address=").append(address); - sb.append(", age=").append(age); - sb.append("]"); - return sb.toString(); - } -} diff --git a/spring-boot-mybatis/src/main/java/alex/dto/PersonExample.java b/spring-boot-mybatis/src/main/java/alex/dto/PersonExample.java deleted file mode 100644 index 6423b2b..0000000 --- a/spring-boot-mybatis/src/main/java/alex/dto/PersonExample.java +++ /dev/null @@ -1,565 +0,0 @@ -package alex.dto; - -import java.util.ArrayList; -import java.util.List; - -public class PersonExample { - - /** - * This field was generated by MyBatis Generator. This field corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - protected String orderByClause; - - /** - * This field was generated by MyBatis Generator. This field corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - protected boolean distinct; - - /** - * This field was generated by MyBatis Generator. This field corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - protected List oredCriteria; - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public PersonExample() { - oredCriteria = new ArrayList(); - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public String getOrderByClause() { - return orderByClause; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public void setOrderByClause(String orderByClause) { - this.orderByClause = orderByClause; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public boolean isDistinct() { - return distinct; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public void setDistinct(boolean distinct) { - this.distinct = distinct; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public List getOredCriteria() { - return oredCriteria; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public void or(Criteria criteria) { - oredCriteria.add(criteria); - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public Criteria or() { - Criteria criteria = createCriteriaInternal(); - oredCriteria.add(criteria); - return criteria; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public Criteria createCriteria() { - Criteria criteria = createCriteriaInternal(); - if (oredCriteria.size() == 0) { - oredCriteria.add(criteria); - } - return criteria; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - protected Criteria createCriteriaInternal() { - Criteria criteria = new Criteria(); - return criteria; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public void clear() { - oredCriteria.clear(); - orderByClause = null; - distinct = false; - } - - /** - * This class was generated by MyBatis Generator. This class corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - protected abstract static class GeneratedCriteria { - - protected List criteria; - - protected GeneratedCriteria() { - super(); - criteria = new ArrayList(); - } - - public boolean isValid() { - return criteria.size() > 0; - } - - public List getAllCriteria() { - return criteria; - } - - public List getCriteria() { - return criteria; - } - - protected void addCriterion(String condition) { - if (condition == null) { - throw new RuntimeException("Value for condition cannot be null"); - } - criteria.add(new Criterion(condition)); - } - - protected void addCriterion(String condition, Object value, String property) { - if (value == null) { - throw new RuntimeException("Value for " + property + " cannot be null"); - } - criteria.add(new Criterion(condition, value)); - } - - protected void addCriterion(String condition, Object value1, Object value2, String property) { - if (value1 == null || value2 == null) { - throw new RuntimeException("Between values for " + property + " cannot be null"); - } - criteria.add(new Criterion(condition, value1, value2)); - } - - public Criteria andIdIsNull() { - addCriterion("id is null"); - return (Criteria) this; - } - - public Criteria andIdIsNotNull() { - addCriterion("id is not null"); - return (Criteria) this; - } - - public Criteria andIdEqualTo(Integer value) { - addCriterion("id =", value, "id"); - return (Criteria) this; - } - - public Criteria andIdNotEqualTo(Integer value) { - addCriterion("id <>", value, "id"); - return (Criteria) this; - } - - public Criteria andIdGreaterThan(Integer value) { - addCriterion("id >", value, "id"); - return (Criteria) this; - } - - public Criteria andIdGreaterThanOrEqualTo(Integer value) { - addCriterion("id >=", value, "id"); - return (Criteria) this; - } - - public Criteria andIdLessThan(Integer value) { - addCriterion("id <", value, "id"); - return (Criteria) this; - } - - public Criteria andIdLessThanOrEqualTo(Integer value) { - addCriterion("id <=", value, "id"); - return (Criteria) this; - } - - public Criteria andIdIn(List values) { - addCriterion("id in", values, "id"); - return (Criteria) this; - } - - public Criteria andIdNotIn(List values) { - addCriterion("id not in", values, "id"); - return (Criteria) this; - } - - public Criteria andIdBetween(Integer value1, Integer value2) { - addCriterion("id between", value1, value2, "id"); - return (Criteria) this; - } - - public Criteria andIdNotBetween(Integer value1, Integer value2) { - addCriterion("id not between", value1, value2, "id"); - return (Criteria) this; - } - - public Criteria andNameIsNull() { - addCriterion("name is null"); - return (Criteria) this; - } - - public Criteria andNameIsNotNull() { - addCriterion("name is not null"); - return (Criteria) this; - } - - public Criteria andNameEqualTo(String value) { - addCriterion("name =", value, "name"); - return (Criteria) this; - } - - public Criteria andNameNotEqualTo(String value) { - addCriterion("name <>", value, "name"); - return (Criteria) this; - } - - public Criteria andNameGreaterThan(String value) { - addCriterion("name >", value, "name"); - return (Criteria) this; - } - - public Criteria andNameGreaterThanOrEqualTo(String value) { - addCriterion("name >=", value, "name"); - return (Criteria) this; - } - - public Criteria andNameLessThan(String value) { - addCriterion("name <", value, "name"); - return (Criteria) this; - } - - public Criteria andNameLessThanOrEqualTo(String value) { - addCriterion("name <=", value, "name"); - return (Criteria) this; - } - - public Criteria andNameLike(String value) { - addCriterion("name like", value, "name"); - return (Criteria) this; - } - - public Criteria andNameNotLike(String value) { - addCriterion("name not like", value, "name"); - return (Criteria) this; - } - - public Criteria andNameIn(List values) { - addCriterion("name in", values, "name"); - return (Criteria) this; - } - - public Criteria andNameNotIn(List values) { - addCriterion("name not in", values, "name"); - return (Criteria) this; - } - - public Criteria andNameBetween(String value1, String value2) { - addCriterion("name between", value1, value2, "name"); - return (Criteria) this; - } - - public Criteria andNameNotBetween(String value1, String value2) { - addCriterion("name not between", value1, value2, "name"); - return (Criteria) this; - } - - public Criteria andAddressIsNull() { - addCriterion("address is null"); - return (Criteria) this; - } - - public Criteria andAddressIsNotNull() { - addCriterion("address is not null"); - return (Criteria) this; - } - - public Criteria andAddressEqualTo(String value) { - addCriterion("address =", value, "address"); - return (Criteria) this; - } - - public Criteria andAddressNotEqualTo(String value) { - addCriterion("address <>", value, "address"); - return (Criteria) this; - } - - public Criteria andAddressGreaterThan(String value) { - addCriterion("address >", value, "address"); - return (Criteria) this; - } - - public Criteria andAddressGreaterThanOrEqualTo(String value) { - addCriterion("address >=", value, "address"); - return (Criteria) this; - } - - public Criteria andAddressLessThan(String value) { - addCriterion("address <", value, "address"); - return (Criteria) this; - } - - public Criteria andAddressLessThanOrEqualTo(String value) { - addCriterion("address <=", value, "address"); - return (Criteria) this; - } - - public Criteria andAddressLike(String value) { - addCriterion("address like", value, "address"); - return (Criteria) this; - } - - public Criteria andAddressNotLike(String value) { - addCriterion("address not like", value, "address"); - return (Criteria) this; - } - - public Criteria andAddressIn(List values) { - addCriterion("address in", values, "address"); - return (Criteria) this; - } - - public Criteria andAddressNotIn(List values) { - addCriterion("address not in", values, "address"); - return (Criteria) this; - } - - public Criteria andAddressBetween(String value1, String value2) { - addCriterion("address between", value1, value2, "address"); - return (Criteria) this; - } - - public Criteria andAddressNotBetween(String value1, String value2) { - addCriterion("address not between", value1, value2, "address"); - return (Criteria) this; - } - - public Criteria andAgeIsNull() { - addCriterion("age is null"); - return (Criteria) this; - } - - public Criteria andAgeIsNotNull() { - addCriterion("age is not null"); - return (Criteria) this; - } - - public Criteria andAgeEqualTo(Integer value) { - addCriterion("age =", value, "age"); - return (Criteria) this; - } - - public Criteria andAgeNotEqualTo(Integer value) { - addCriterion("age <>", value, "age"); - return (Criteria) this; - } - - public Criteria andAgeGreaterThan(Integer value) { - addCriterion("age >", value, "age"); - return (Criteria) this; - } - - public Criteria andAgeGreaterThanOrEqualTo(Integer value) { - addCriterion("age >=", value, "age"); - return (Criteria) this; - } - - public Criteria andAgeLessThan(Integer value) { - addCriterion("age <", value, "age"); - return (Criteria) this; - } - - public Criteria andAgeLessThanOrEqualTo(Integer value) { - addCriterion("age <=", value, "age"); - return (Criteria) this; - } - - public Criteria andAgeIn(List values) { - addCriterion("age in", values, "age"); - return (Criteria) this; - } - - public Criteria andAgeNotIn(List values) { - addCriterion("age not in", values, "age"); - return (Criteria) this; - } - - public Criteria andAgeBetween(Integer value1, Integer value2) { - addCriterion("age between", value1, value2, "age"); - return (Criteria) this; - } - - public Criteria andAgeNotBetween(Integer value1, Integer value2) { - addCriterion("age not between", value1, value2, "age"); - return (Criteria) this; - } - } - - /** - * This class was generated by MyBatis Generator. This class corresponds to the database table - * person - * - * @mbg.generated do_not_delete_during_merge Fri Oct 06 09:41:17 CST 2017 - */ - public static class Criteria extends GeneratedCriteria { - - protected Criteria() { - super(); - } - } - - /** - * This class was generated by MyBatis Generator. This class corresponds to the database table - * person - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public static class Criterion { - - private String condition; - - private Object value; - - private Object secondValue; - - private boolean noValue; - - private boolean singleValue; - - private boolean betweenValue; - - private boolean listValue; - - private String typeHandler; - - protected Criterion(String condition) { - super(); - this.condition = condition; - this.typeHandler = null; - this.noValue = true; - } - - protected Criterion(String condition, Object value, String typeHandler) { - super(); - this.condition = condition; - this.value = value; - this.typeHandler = typeHandler; - if (value instanceof List) { - this.listValue = true; - } else { - this.singleValue = true; - } - } - - protected Criterion(String condition, Object value) { - this(condition, value, null); - } - - protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { - super(); - this.condition = condition; - this.value = value; - this.secondValue = secondValue; - this.typeHandler = typeHandler; - this.betweenValue = true; - } - - protected Criterion(String condition, Object value, Object secondValue) { - this(condition, value, secondValue, null); - } - - public String getCondition() { - return condition; - } - - public Object getValue() { - return value; - } - - public Object getSecondValue() { - return secondValue; - } - - public boolean isNoValue() { - return noValue; - } - - public boolean isSingleValue() { - return singleValue; - } - - public boolean isBetweenValue() { - return betweenValue; - } - - public boolean isListValue() { - return listValue; - } - - public String getTypeHandler() { - return typeHandler; - } - } -} diff --git a/spring-boot-mybatis/src/main/java/alex/dto/School.java b/spring-boot-mybatis/src/main/java/alex/dto/School.java deleted file mode 100644 index 38cc2e5..0000000 --- a/spring-boot-mybatis/src/main/java/alex/dto/School.java +++ /dev/null @@ -1,104 +0,0 @@ -package alex.dto; - -public class School { - - /** - * This field was generated by MyBatis Generator. This field corresponds to the database column - * school.id - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - private Integer id; - - /** - * This field was generated by MyBatis Generator. This field corresponds to the database column - * school.name - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - private String name; - - /** - * This method was generated by MyBatis Generator. This method returns the value of the database - * column school.id - * - * @return the value of school.id - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public Integer getId() { - return id; - } - - /** - * This method was generated by MyBatis Generator. This method sets the value of the database - * column school.id - * - * @param id the value for school.id - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public void setId(Integer id) { - this.id = id; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public School withId(Integer id) { - this.setId(id); - return this; - } - - /** - * This method was generated by MyBatis Generator. This method returns the value of the database - * column school.name - * - * @return the value of school.name - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public String getName() { - return name; - } - - /** - * This method was generated by MyBatis Generator. This method sets the value of the database - * column school.name - * - * @param name the value for school.name - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public void setName(String name) { - this.name = name == null ? null : name.trim(); - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public School withName(String name) { - this.setName(name); - return this; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(getClass().getSimpleName()); - sb.append(" ["); - sb.append("Hash = ").append(hashCode()); - sb.append(", id=").append(id); - sb.append(", name=").append(name); - sb.append("]"); - return sb.toString(); - } -} diff --git a/spring-boot-mybatis/src/main/java/alex/dto/SchoolExample.java b/spring-boot-mybatis/src/main/java/alex/dto/SchoolExample.java deleted file mode 100644 index 79a0235..0000000 --- a/spring-boot-mybatis/src/main/java/alex/dto/SchoolExample.java +++ /dev/null @@ -1,435 +0,0 @@ -package alex.dto; - -import java.util.ArrayList; -import java.util.List; - -public class SchoolExample { - - /** - * This field was generated by MyBatis Generator. This field corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - protected String orderByClause; - - /** - * This field was generated by MyBatis Generator. This field corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - protected boolean distinct; - - /** - * This field was generated by MyBatis Generator. This field corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - protected List oredCriteria; - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public SchoolExample() { - oredCriteria = new ArrayList(); - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public String getOrderByClause() { - return orderByClause; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public void setOrderByClause(String orderByClause) { - this.orderByClause = orderByClause; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public boolean isDistinct() { - return distinct; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public void setDistinct(boolean distinct) { - this.distinct = distinct; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public List getOredCriteria() { - return oredCriteria; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public void or(Criteria criteria) { - oredCriteria.add(criteria); - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public Criteria or() { - Criteria criteria = createCriteriaInternal(); - oredCriteria.add(criteria); - return criteria; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public Criteria createCriteria() { - Criteria criteria = createCriteriaInternal(); - if (oredCriteria.size() == 0) { - oredCriteria.add(criteria); - } - return criteria; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - protected Criteria createCriteriaInternal() { - Criteria criteria = new Criteria(); - return criteria; - } - - /** - * This method was generated by MyBatis Generator. This method corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public void clear() { - oredCriteria.clear(); - orderByClause = null; - distinct = false; - } - - /** - * This class was generated by MyBatis Generator. This class corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - protected abstract static class GeneratedCriteria { - - protected List criteria; - - protected GeneratedCriteria() { - super(); - criteria = new ArrayList(); - } - - public boolean isValid() { - return criteria.size() > 0; - } - - public List getAllCriteria() { - return criteria; - } - - public List getCriteria() { - return criteria; - } - - protected void addCriterion(String condition) { - if (condition == null) { - throw new RuntimeException("Value for condition cannot be null"); - } - criteria.add(new Criterion(condition)); - } - - protected void addCriterion(String condition, Object value, String property) { - if (value == null) { - throw new RuntimeException("Value for " + property + " cannot be null"); - } - criteria.add(new Criterion(condition, value)); - } - - protected void addCriterion(String condition, Object value1, Object value2, String property) { - if (value1 == null || value2 == null) { - throw new RuntimeException("Between values for " + property + " cannot be null"); - } - criteria.add(new Criterion(condition, value1, value2)); - } - - public Criteria andIdIsNull() { - addCriterion("id is null"); - return (Criteria) this; - } - - public Criteria andIdIsNotNull() { - addCriterion("id is not null"); - return (Criteria) this; - } - - public Criteria andIdEqualTo(Integer value) { - addCriterion("id =", value, "id"); - return (Criteria) this; - } - - public Criteria andIdNotEqualTo(Integer value) { - addCriterion("id <>", value, "id"); - return (Criteria) this; - } - - public Criteria andIdGreaterThan(Integer value) { - addCriterion("id >", value, "id"); - return (Criteria) this; - } - - public Criteria andIdGreaterThanOrEqualTo(Integer value) { - addCriterion("id >=", value, "id"); - return (Criteria) this; - } - - public Criteria andIdLessThan(Integer value) { - addCriterion("id <", value, "id"); - return (Criteria) this; - } - - public Criteria andIdLessThanOrEqualTo(Integer value) { - addCriterion("id <=", value, "id"); - return (Criteria) this; - } - - public Criteria andIdIn(List values) { - addCriterion("id in", values, "id"); - return (Criteria) this; - } - - public Criteria andIdNotIn(List values) { - addCriterion("id not in", values, "id"); - return (Criteria) this; - } - - public Criteria andIdBetween(Integer value1, Integer value2) { - addCriterion("id between", value1, value2, "id"); - return (Criteria) this; - } - - public Criteria andIdNotBetween(Integer value1, Integer value2) { - addCriterion("id not between", value1, value2, "id"); - return (Criteria) this; - } - - public Criteria andNameIsNull() { - addCriterion("name is null"); - return (Criteria) this; - } - - public Criteria andNameIsNotNull() { - addCriterion("name is not null"); - return (Criteria) this; - } - - public Criteria andNameEqualTo(String value) { - addCriterion("name =", value, "name"); - return (Criteria) this; - } - - public Criteria andNameNotEqualTo(String value) { - addCriterion("name <>", value, "name"); - return (Criteria) this; - } - - public Criteria andNameGreaterThan(String value) { - addCriterion("name >", value, "name"); - return (Criteria) this; - } - - public Criteria andNameGreaterThanOrEqualTo(String value) { - addCriterion("name >=", value, "name"); - return (Criteria) this; - } - - public Criteria andNameLessThan(String value) { - addCriterion("name <", value, "name"); - return (Criteria) this; - } - - public Criteria andNameLessThanOrEqualTo(String value) { - addCriterion("name <=", value, "name"); - return (Criteria) this; - } - - public Criteria andNameLike(String value) { - addCriterion("name like", value, "name"); - return (Criteria) this; - } - - public Criteria andNameNotLike(String value) { - addCriterion("name not like", value, "name"); - return (Criteria) this; - } - - public Criteria andNameIn(List values) { - addCriterion("name in", values, "name"); - return (Criteria) this; - } - - public Criteria andNameNotIn(List values) { - addCriterion("name not in", values, "name"); - return (Criteria) this; - } - - public Criteria andNameBetween(String value1, String value2) { - addCriterion("name between", value1, value2, "name"); - return (Criteria) this; - } - - public Criteria andNameNotBetween(String value1, String value2) { - addCriterion("name not between", value1, value2, "name"); - return (Criteria) this; - } - } - - /** - * This class was generated by MyBatis Generator. This class corresponds to the database table - * school - * - * @mbg.generated do_not_delete_during_merge Fri Oct 06 09:41:17 CST 2017 - */ - public static class Criteria extends GeneratedCriteria { - - protected Criteria() { - super(); - } - } - - /** - * This class was generated by MyBatis Generator. This class corresponds to the database table - * school - * - * @mbg.generated Fri Oct 06 09:41:17 CST 2017 - */ - public static class Criterion { - - private String condition; - - private Object value; - - private Object secondValue; - - private boolean noValue; - - private boolean singleValue; - - private boolean betweenValue; - - private boolean listValue; - - private String typeHandler; - - protected Criterion(String condition) { - super(); - this.condition = condition; - this.typeHandler = null; - this.noValue = true; - } - - protected Criterion(String condition, Object value, String typeHandler) { - super(); - this.condition = condition; - this.value = value; - this.typeHandler = typeHandler; - if (value instanceof List) { - this.listValue = true; - } else { - this.singleValue = true; - } - } - - protected Criterion(String condition, Object value) { - this(condition, value, null); - } - - protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { - super(); - this.condition = condition; - this.value = value; - this.secondValue = secondValue; - this.typeHandler = typeHandler; - this.betweenValue = true; - } - - protected Criterion(String condition, Object value, Object secondValue) { - this(condition, value, secondValue, null); - } - - public String getCondition() { - return condition; - } - - public Object getValue() { - return value; - } - - public Object getSecondValue() { - return secondValue; - } - - public boolean isNoValue() { - return noValue; - } - - public boolean isSingleValue() { - return singleValue; - } - - public boolean isBetweenValue() { - return betweenValue; - } - - public boolean isListValue() { - return listValue; - } - - public String getTypeHandler() { - return typeHandler; - } - } -} diff --git a/spring-boot-mybatis/src/main/resources/alex/dao/PersonMapper.xml b/spring-boot-mybatis/src/main/resources/alex/dao/PersonMapper.xml deleted file mode 100644 index df9d40f..0000000 --- a/spring-boot-mybatis/src/main/resources/alex/dao/PersonMapper.xml +++ /dev/null @@ -1,267 +0,0 @@ - - - - - - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - - - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - - - - - - - - - - id, name, address, age - - - - - - DELETE FROM person - WHERE id = #{id,jdbcType=INTEGER} - - - - delete from person - - - - - - - insert into person (name, address, age - ) - values (#{name,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER} - ) - - - - insert into person - - - name, - - - address, - - - age, - - - - - #{name,jdbcType=VARCHAR}, - - - #{address,jdbcType=VARCHAR}, - - - #{age,jdbcType=INTEGER}, - - - - - - - update person - - - id = #{record.id,jdbcType=INTEGER}, - - - name = #{record.name,jdbcType=VARCHAR}, - - - address = #{record.address,jdbcType=VARCHAR}, - - - age = #{record.age,jdbcType=INTEGER}, - - - - - - - - - update person - set id = #{record.id,jdbcType=INTEGER}, - name = #{record.name,jdbcType=VARCHAR}, - address = #{record.address,jdbcType=VARCHAR}, - age = #{record.age,jdbcType=INTEGER} - - - - - - - update person - - - name = #{name,jdbcType=VARCHAR}, - - - address = #{address,jdbcType=VARCHAR}, - - - age = #{age,jdbcType=INTEGER}, - - - where id = #{id,jdbcType=INTEGER} - - - - UPDATE person - SET name = #{name,jdbcType=VARCHAR}, - address = #{address,jdbcType=VARCHAR}, - age = #{age,jdbcType=INTEGER} - WHERE id = #{id,jdbcType=INTEGER} - - \ No newline at end of file diff --git a/spring-boot-mybatis/src/main/resources/alex/dao/SchoolMapper.xml b/spring-boot-mybatis/src/main/resources/alex/dao/SchoolMapper.xml deleted file mode 100644 index a42bacc..0000000 --- a/spring-boot-mybatis/src/main/resources/alex/dao/SchoolMapper.xml +++ /dev/null @@ -1,235 +0,0 @@ - - - - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - - - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - - - - - - - - - - id, name - - - - - - DELETE FROM school - WHERE id = #{id,jdbcType=INTEGER} - - - - delete from school - - - - - - - insert into school (name) - values (#{name,jdbcType=VARCHAR}) - - - - insert into school - - - name, - - - - - #{name,jdbcType=VARCHAR}, - - - - - - - update school - - - id = #{record.id,jdbcType=INTEGER}, - - - name = #{record.name,jdbcType=VARCHAR}, - - - - - - - - - update school - set id = #{record.id,jdbcType=INTEGER}, - name = #{record.name,jdbcType=VARCHAR} - - - - - - - update school - - - name = #{name,jdbcType=VARCHAR}, - - - where id = #{id,jdbcType=INTEGER} - - - - UPDATE school - SET name = #{name,jdbcType=VARCHAR} - WHERE id = #{id,jdbcType=INTEGER} - - \ No newline at end of file diff --git a/spring-boot-mybatis/src/main/resources/application.yml b/spring-boot-mybatis/src/main/resources/application.yml deleted file mode 100644 index 7e8e060..0000000 --- a/spring-boot-mybatis/src/main/resources/application.yml +++ /dev/null @@ -1,11 +0,0 @@ -debug: false -mybatis: - type-aliases-package: alex.dto -spring: - datasource: - driver-class-name: com.mysql.jdbc.Driver - url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowMultiQueries=true - username: root - password: root - main: - banner-mode: off \ No newline at end of file diff --git a/spring-boot-mybatis/src/main/resources/generatorConfig.properties b/spring-boot-mybatis/src/main/resources/generatorConfig.properties deleted file mode 100644 index c80fba7..0000000 --- a/spring-boot-mybatis/src/main/resources/generatorConfig.properties +++ /dev/null @@ -1,11 +0,0 @@ -jdbc.driver=com.mysql.jdbc.Driver -jdbc.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true -jdbc.user=root -jdbc.password=root -model.target.package=alex.dto -model.target.project=src/main/java -dao.target.package=alex.dao -dao.target.project=src/main/java -mapper.target.package=alex.dao -mapper.target.project=src/main/resources -