Skip to content

Code Generator

zzg edited this page Mar 31, 2017 · 39 revisions

Code generator

Java Build

@DB(url="jdbc:mysql://127.0.0.1:3306/test",username="root",  password="root")
public interface TestDB {        
    public static DBConfig DB=DBConfig.fromClass(TestDB.class);
	               
    public static class Generate{        
      public static void main(String[] args) { 
          //Generate Model classes to directory: src/main/java OR src  
          DBModelGenerateMain.generateModelClass(TestDB.class);		          
      }  
    }
}

Maven Build

<plugins>
    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
            <annotationProcessors>
                <annotationProcessor>
                    com.tsc9526.monalisa.orm.processor.DBAnnotationProcessor
                </annotationProcessor>
            </annotationProcessors>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
            <execution>
                <id>copy-resources</id>
                <phase>compile</phase>
                <goals>
                    goal>copy-resources</goal>
                </goals>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <outputDirectory>${basedir}/target/classes</outputDirectory>
                    <resources>
                        <resource>
                            <directory>target/generated-sources/annotations</directory>
                            <excludes>
                                <exclude>**/*.java</exclude>
                            </excludes>
                            <filtering>false</filtering>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

Eclipse Plugin

Drag to your running Eclipse workspace to install monalisa-orm

OR

  • Download plugin ,Place the jar to : eclipse/plugins
  • Restart Eclipse

Plugin source code

Auto-generate model classes (Saved: Ctrl+S)

  • Need to set up project(Properties->Java Compiler)

    JDK compliance: >= 1.6

  • Need to set up project(Properties->Java Compiler->Annotation Processing)

    Enable this option: Enable annotation processing

Like this:

image

Auto-Generate DTOs

  • Need to set up eclipse (Window->Preferences->Java->Editor->Save Action -> Configure -> monalisa)

    Enable this option: @Select

Like this:

image

Multiline String

Plugin installed, you can write multiline strings. For detail: Multiline Syntax

Effect as shown below:

image

You can’t perform that action at this time.