国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - 基于Mybatis plus 自動代碼生成器的實現(xiàn)代碼

基于Mybatis plus 自動代碼生成器的實現(xiàn)代碼

2021-04-30 14:30夏天的尾巴ljh Java教程

本文通過實例代碼給大家介紹了基于Mybatis-plus 自動代碼生成器的相關知識,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下

1.使用的是maven項目,添加依賴

?
1
2
3
4
5
6
<!-- mybatis-plus begin -->
   <dependency>
     <groupid>com.baomidou</groupid>
     <artifactid>mybatis-plus</artifactid>
     <version>2.2.0</version>
   </dependency>

還有數(shù)據(jù)庫的連接

?
1
2
3
4
5
<dependency>
    <groupid>mysql</groupid>
    <artifactid>mysql-connector-java</artifactid>
    <scope>compile</scope>
</dependency>

最后是源碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import com.baomidou.mybatisplus.generator.autogenerator;
import com.baomidou.mybatisplus.generator.config.datasourceconfig;
import com.baomidou.mybatisplus.generator.config.globalconfig;
import com.baomidou.mybatisplus.generator.config.packageconfig;
import com.baomidou.mybatisplus.generator.config.strategyconfig;
import com.baomidou.mybatisplus.generator.config.rules.dbtype;
import com.baomidou.mybatisplus.generator.config.rules.namingstrategy;
import org.junit.jupiter.api.test;
/**
 * mybatis-plus 自動生成代碼
 *
 * @author terry
 * @version 1.0
 * @date 2018-05-16 09:35
 */
public class simplemp {
  @test
  public void generatecode() {
    //指定包名
    string packagename = "com.hciot.hhhh";
    //user -> userservice, 設置成true: user -> iuserservice
    boolean servicenamestartwithi = false;
    //指定生成的表名
    string[] tablenames = new string[]{"data_air_sensor_co", "order_product", "relation_device_gateway"};
    generatebytables(servicenamestartwithi, packagename, tablenames);
  }
  /**
   * 根據(jù)表自動生成
   *
   * @param servicenamestartwithi 默認為false
   * @param packagename      包名
   * @param tablenames      表名
   * @author terry
   */
  private void generatebytables(boolean servicenamestartwithi, string packagename, string... tablenames) {
    //配置數(shù)據(jù)源
    datasourceconfig datasourceconfig = getdatasourceconfig();
    // 策略配置
    strategyconfig strategyconfig = getstrategyconfig(tablenames);
    //全局變量配置
    globalconfig globalconfig = getglobalconfig(servicenamestartwithi);
    //包名配置
    packageconfig packageconfig = getpackageconfig(packagename);
    //自動生成
    atuogenerator(datasourceconfig, strategyconfig, globalconfig, packageconfig);
  }
  /**
   * 集成
   *
   * @param datasourceconfig 配置數(shù)據(jù)源
   * @param strategyconfig  策略配置
   * @param config      全局變量配置
   * @param packageconfig  包名配置
   * @author terry
   */
  private void atuogenerator(datasourceconfig datasourceconfig, strategyconfig strategyconfig, globalconfig config, packageconfig packageconfig) {
    new autogenerator()
        .setglobalconfig(config)
        .setdatasource(datasourceconfig)
        .setstrategy(strategyconfig)
        .setpackageinfo(packageconfig)
        .execute();
  }
  /**
   * 設置包名
   *
   * @param packagename 父路徑包名
   * @return packageconfig 包名配置
   * @author terry
   */
  private packageconfig getpackageconfig(string packagename) {
    return new packageconfig()
        .setparent(packagename)
        .setxml("mapper")
        .setmapper("dao")
        .setcontroller("controller")
        .setentity("entity");
  }
  /**
   * 全局配置
   *
   * @param servicenamestartwithi false
   * @return globalconfig
   * @author terry
   */
  private globalconfig getglobalconfig(boolean servicenamestartwithi) {
    globalconfig globalconfig = new globalconfig();
    globalconfig
        .setbasecolumnlist(true)
        .setbaseresultmap(true)
        .setactiverecord(false)
        .setauthor("terry")
        //設置輸出路徑
        .setoutputdir(getoutputdir("mybatis-plus"))
        .setfileoverride(true);
    if (!servicenamestartwithi) {
      //設置service名
      globalconfig.setservicename("%sservice");
    }
    return globalconfig;
  }
  /**
   * 返回項目路徑
   *
   * @param projectname 項目名
   * @return 項目路徑
   * @author terry
   */
  private string getoutputdir(string projectname) {
    string path = this.getclass().getclassloader().getresource("").getpath();
    int index = path.indexof(projectname);
    return path.substring(1, index) + projectname + "/src/main/java/";
  }
  /**
   * 策略配置
   *
   * @param tablenames 表名
   * @return strategyconfig
   * @author terry
   */
  private strategyconfig getstrategyconfig(string... tablenames) {
    return new strategyconfig()
        // 全局大寫命名 oracle 注意
        .setcapitalmode(true)
        .setentitylombokmodel(false)
        // 表名、字段名、是否使用下劃線命名(默認 false)
        .setdbcolumnunderline(true)
        //從數(shù)據(jù)庫表到文件的命名策略
        .setnaming(namingstrategy.underline_to_camel)
        //需要生成的的表名,多個表名傳數(shù)組
        .setinclude(tablenames);
  }
  /**
   * 配置數(shù)據(jù)源
   *
   * @return 數(shù)據(jù)源配置 datasourceconfig
   * @author terry
   */
  private datasourceconfig getdatasourceconfig() {
    string dburl = "jdbc:mysql://localhost:3306/test";
    return new datasourceconfig().setdbtype(dbtype.mysql)
        .seturl(dburl)
        .setusername("root")
        .setpassword("root")
        .setdrivername("com.mysql.jdbc.driver");
  }
  /**
   * 根據(jù)表自動生成
   *
   * @param packagename 包名
   * @param tablenames 表名
   * @author terry
   */
  @suppresswarnings("unused")
  private void generatebytables(string packagename, string... tablenames) {
    generatebytables(true, packagename, tablenames);
  }
}

總結

以上所述是小編給大家介紹的基于mybatis plus 自動代碼生成器的實現(xiàn)代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網(wǎng)站的支持!

原文鏈接:https://blog.csdn.net/weixin_41685100/article/details/80342246

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲色图二区 | 国产成人免费 | 亚洲国产精品久久久 | 精品国产一级 | 91视频免费看 | 国产精品久久久久久婷婷天堂 | 中文字幕第一区 | av中文字幕在线 | 九一视频在线观看 | 精品久久久久一区二区国产 | 亚洲成人在线观看视频 | 中文字幕一区二区三区久久 | 日韩性精品 | 精品国产一区二区三区久久久蜜月 | 精品少妇一区二区三区在线播放 | 久久久亚洲国产天美传媒修理工 | 精品久久久久久久久久久久 | 91仓库| 久久国产精品无码网站 | 日本黄色免费网站 | 欧美综合久久 | 久久九九国产精品 | 中文字幕高清在线 | 亚洲免费在线 | 一区二区三区不卡视频 | 色a在线| 黄站免费| 日韩欧美一区二区在线观看视频 | 国产亚洲精品美女久久久久久久久久 | 精品不卡| 亚洲成人精品一区 | 国产乱码一区二区三区 | 日本韩国欧美一区 | 一区二区在线电影 | 精品久久久久久久 | 中国freesex| 一区二区在线视频 | 中文一区 | 国产精品久久久久精 | 99久久免费看精品国产 | 国产精品久久久久久婷婷天堂 |