SSM框架代码自动生成

项目目录

SSM框架代码自动生成_第1张图片
SSM框架代码自动生成_第2张图片

主要用到两个文件:CodeGeneratorUtil.java \ mbg.xml

CodeGeneratorUtil.java

package sei.util;
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 CodeGeneratorUtil {
    public static void main(String[] args) throws Exception{
        List warnings = new ArrayList();
           boolean overwrite = true;
           File configFile = new File("mbg.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);
           System.out.println("运行完成");
    }

}

mbg.xml 里面这些什么意思等以后再加

"1.0" encoding="UTF-8"?>
"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">



  "DB2Tables" targetRuntime="MyBatis3">

    "com.mysql.jdbc.Driver"
        connectionURL="jdbc:mysql://bj-cdb-go7o8rhh.sql.tencentcdb.com:7275/newmydb"
        userId="root"
        password="WSbfCKDRJ7BzNs9A">
    

    
      "forceBigDecimals" value="false" />
    

    "sei.pojo" targetProject=".\src">
      "enableSubPackages" value="true" />
      "trimStrings" value="true" />
    

    "sei.mapping"  targetProject=".\src">
      "enableSubPackages" value="true" />
    

    "XMLMAPPER" targetPackage="sei.dao"  targetProject=".\src">
      "enableSubPackages" value="true" />
    

    "DB2ADMIN" tableName="addr_batch" domainObjectName="AddrBatch">

我每次自动生成表需要修改的文件及内容记录一下

SystemHasUser.java

//部分代码
    private Integer countyId;

    private County county;

    private City city;       

    private User user;

    private LoginRemark loginRemark;

    private System system;

    private Company company;

    private DataTable userStatus; 

    public DataTable getUserStatus() {
        return userStatus;
    }

    public void setUserStatus(DataTable userStatus) {
        this.userStatus = userStatus;
    }

SystemHasUserExample.java

protected Integer start;
    protected Integer limit;

    public Integer getStart() {
        return start;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

SystemHasUserMapper.java

List selectIdByExample(SystemHasUserExample example);

SystemHasUserMapper.xml

// 只截取了部分代码
"userStatus" column="userStatus_id" select="sei.dao.DataTableMapper.selectUserStatusByCode">
    "company" column="Id" select="sei.dao.CompanyMapper.selectByPrimaryKey">
    "county" column="county_id" select="sei.dao.CountyMapper.selectByPrimaryKey">
    "city" column="city_id" select="sei.dao.CityMapper.selectByPrimaryKey">
    "user" column="User_Id" select="sei.dao.UserMapper.selectByPrimaryKey">
    "system" column="System_Id" select="sei.dao.SystemMapper.selectByPrimaryKey">
    "loginRemark" column="remark_id" select="sei.dao.LoginRemarkMapper.selectByPrimaryKey">


<if test="start != null and limit !=null and limit!=0">
     limit #{start},#{limit}
    if>
    <if test="start == null and limit !=null and limit!=0">
     limit #{limit}
    if>

useGeneratedKeys="true" keyColumn="Id" keyProperty="id"

你可能感兴趣的:(SSM框架)