spring-boot开发微信小程序后台(二)

spring-boot开发微信小程序后台

spring boot与mybatis整合,mybatis逆向工程生成pojo、mapper、dao

逆向工程目录结构:

spring-boot开发微信小程序后台(二)_第1张图片

pom.xml:


	4.0.0

		cn.zoubin
		0.0.1-SNAPSHOT

	mybatis-generatorConfig
	
	
		UTF-8
	
	
	
			
		
		
		    org.springframework.boot
		    spring-boot-starter-log4j
		    1.3.8.RELEASE
		
		
        
		
            com.alibaba
            druid
            1.1.0
        
        
            com.alibaba
            druid-spring-boot-starter
            1.1.0
        
        
        
            mysql
            mysql-connector-java
            5.1.41
        

        
		
		    org.mybatis.spring.boot
		    mybatis-spring-boot-starter
		    1.3.1
		
		
		
		    tk.mybatis
		    mapper-spring-boot-starter
		    1.2.4
		
		
		
		    com.github.pagehelper
		    pagehelper-spring-boot-starter
		    1.2.3
		
	
		
 		
            org.mybatis.generator
            mybatis-generator-core
            1.3.2
            compile
            true
        
	
	

 GeneratorDisplay:启动类,加载数据库文件。

package cn.zoubin.mybatis.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;


public class GeneratorDisplay {

	public void generator() throws Exception{

		List warnings = new ArrayList();
		boolean overwrite = true;
		//指定 逆向工程配置文件
		File configFile = new File("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(null);

	} 
	
	public static void main(String[] args) throws Exception {
		try {
			GeneratorDisplay generatorSqlmap = new GeneratorDisplay();
			generatorSqlmap.generator();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}

MyMapper:固定接口,生成dao类的继承父类,不能被扫描。

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014-2016 [email protected]
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package cn.zoubin.utils;

import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;

public interface MyMapper extends Mapper, MySqlMapper {
    //TODO
    //FIXME 特别注意,该接口不能被扫描到,否则会出错
}

generatorConfiguration.xml:配置文件,有关数据库,生成内容都在里面。





    
        
        

        
            
        

        
        

        
        

		
        

		
        


		

在配置文件中配置好所有信息后,就可以启动启动类,生成的代码、类都在你指定的包内。

 

你可能感兴趣的:(小程序,java学习)