maven项目自动生成代码(mybatis-generator 代码自动生成)

1.本地安装maven,配置好环境变量
2.在项目下的jdbc文件中引用相关mapper插件:(拷贝以下代码,修改相关路径)
jdbc.driver=com.mysql.jdbc.Driver
	jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode\=true&characterEncoding\=utf8;zeroDateTimeBehavior\=convertToNull
	jdbc.username=root
	jdbc.password=mysql
	
	mapper.plugin = tk.mybatis.mapper.generator.MapperPlugin
	mapper.Mapper = tk.mybatis.mapper.common.Mapper
	#以下注释最后需要使用,使用时不要注释(#)
	#mvn mybatis-generator:generate

3.在项目文件的pom.xml中配置好接口和实体类和mapper.xml的生成路径


		
        ${basedir}/src/main/java
        E:\qdg\workspace_qdpwlds00\bbc-api/src/main/java
        com.qdport.bbc.dao
        com.qdport.bbc.bean
        
        com.qdport.bbc.mapping
	

在项目的pom.xml中配置 generatorConfig的相关插件


		org.mybatis.generator
		mybatis-generator-maven-plugin
		1.3.2
		
			${basedir}/src/main/resources/generator/generatorConfig.xml
			true
			true
		
		
			
				mysql
				mysql-connector-java
				${mysql.version}
			
			
				tk.mybatis
				mapper
				${mapper.version}
			
		
	

4.在项目resource的文件夹中,新建generatorConfiguration.xml文件,引用jdbc配置文件,并设置需要生成的表及实体类名称 代码如下:






  
  

  
  	
    
    
    
    
      
    

    
    

    

    

    
    
	
    
    

一切配置完成之后,选中项目,右键→Show In→Terminal 出来Terminal控制台后
然后将jdbc下的那段代码拷过来:mvn mybatis-generator:generate   右键粘贴(控制台不能Ctrl+v) 然后回车
等到控制台打印出:
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.807 s
[INFO] Finished at: 2017-11-23T13:58:29+08:00
[INFO] Final Memory: 9M/119M
表示相关代码生成完毕,刷新项目便可看到

相关文件如图:

maven项目自动生成代码(mybatis-generator 代码自动生成)_第1张图片

相关操作如图:

maven项目自动生成代码(mybatis-generator 代码自动生成)_第2张图片

pom源代码:


	4.0.0
	com.qdport
	bbc-service
	war
	1.0.0
	bbc-service
	http://maven.apache.org
	
		
        ${basedir}/src/main/java
        E:\qdg\workspace_qdpwlds00\bbc-api/src/main/java
        com.qdport.bbc.dao
        com.qdport.bbc.bean
        
        com.qdport.bbc.mapping
        
		4.2.5.RELEASE
		3.3.1
		5.1.30
		1.2.4
		1.0.18
		1.6.6
		1.2.12
		3.3.6
        5.0.0
	
	
		
			sonatype-nexus-snapshots
			Sonatype Nexus Snapshots
			http://oss.sonatype.org/content/repositories/snapshots
			
				false
			
			
				true
			
		
	
	
		
		    junit
		    junit
		    4.12
		
		
			org.springframework
			spring-test
			 ${spring.version}
			test
		
		
		
			org.mockito
			mockito-core
			1.9.5
			test
		

		
			com.alibaba
			druid
			${druid.version}
		

		
			org.springframework
			spring-core
			${spring.version}
		

		
			org.springframework
			spring-webmvc
			${spring.version}
		

		
			org.springframework
			spring-jdbc
			${spring.version}
		

		
			org.springframework
			spring-tx
			${spring.version}
		

		
			org.aspectj
			aspectjweaver
			1.8.9
		

		
			org.mybatis
			mybatis
			${mybatis.version}
		

		
			org.mybatis
			mybatis-spring
			${mybatisspring.version}
		

		
			com.alibaba
			fastjson
			1.2.4
		

		
			mysql
			mysql-connector-java
			${mysql.version}
		

		
			com.alibaba
			hsf.schema
			edas1.0.0
		

		
			commons-io
			commons-io
			2.4
		

		
			commons-codec
			commons-codec
			1.8
		

		
			com.aliyun.openservices
			aliyun-openservices
			1.0.10
		

		
			commons-fileupload
			commons-fileupload
			1.2.2
		

		
			commons-collections
			commons-collections
			3.2.1
		

		
			org.apache.commons
			commons-pool2
			2.2
		

		
			javax.servlet
			javax.servlet-api
			3.0.1
			provided
		

		
			commons-lang
			commons-lang
			2.6
			jar
			compile
		

		
			org.bouncycastle
			bcprov-jdk15on
			1.47
		

		
			log4j
			log4j
			${log4j.version}
		

		
			org.slf4j
			slf4j-api
			${slf4j.version}
		

		
			org.slf4j
			slf4j-log4j12
			${slf4j.version}
		

		
			com.github.jsqlparser
			jsqlparser
			0.9.4
		

		
			com.github.pagehelper
			pagehelper
			4.1.3
		

		
			javax.persistence
			persistence-api
			1.0
		

		
			com.google.code.gson
			gson
			2.2.4
		
		
			com.github.abel533
			ECharts
			2.2.7
		

		
			org.springframework.session
			spring-session
			1.0.2.RELEASE
		

		
			org.springframework.session
			spring-session-data-redis
			1.0.2.RELEASE
		

		
			redis.clients
			jedis
			2.6.2
		

		
			net.sourceforge.pjl-comp-filter
			pjl-comp-filter
			1.7
		

		
			org.apache.httpcomponents
			httpclient
			4.5.2
		

		
			javax.faces
			jsf-api
			2.1
		

		
			dom4j
			dom4j
			1.6.1
		
		
		
			javax.mail
			mail
			1.4.7
		
		
		
			org.im4java
			im4java
			1.4.0
		
		
		
            org.mybatis.generator
            mybatis-generator-core
            1.3.2
            compile
            true
        
        
		
        
            com.github.pagehelper
            pagehelper
            ${pagehelper.version}
        
        
         
        
            tk.mybatis
            mapper
            ${mapper.version}
        
        
		
		
			com.belerweb
			pinyin4j
			2.5.0
		
		
		
		
			com.qdport
			bbc-api
			1.0.0
		
	
	
		bbc-service
		
			
				src/main/java
				
					**/*.xml
				
			
			
				src/main/resources
				
					*/*.*
				
			
		
		
			
				org.apache.tomcat.maven
				tomcat7-maven-plugin
				2.0-beta-1
				
					8090
					/
					UTF-8
					bbc-service
					tomcat7
				
			
			  
                org.apache.maven.plugins  
                maven-compiler-plugin  
                2.3.2  
                  
                    1.6  
                    1.6  
                  
            
            
                org.mybatis.generator
                mybatis-generator-maven-plugin
                1.3.2
                
                    ${basedir}/src/main/resources/generator/generatorConfig.xml
                    true
                    true
                
                
                    
                        mysql
                        mysql-connector-java
                        ${mysql.version}
                    
                    
                        tk.mybatis
                        mapper
                        ${mapper.version}
                    
                
            
		
	



你可能感兴趣的:(maven)