mysql逆向工程(mybatis plus)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了mysql逆向工程(mybatis plus),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5475字,纯文字阅读大概需要8分钟。
内容图文
![mysql逆向工程(mybatis plus)](/upload/InfoBanner/zyjiaocheng/515/3a87920902c141f4aadcb055e81ccd10.jpg)
1.添加依赖
<!--mybatisplus,加入该jar后,就不再需要mybatis-xxx.jar,mybatis-spring-xxx.jar了,它们会以依赖包的形式被自动维护-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>${mybatisplus.version}</version>
</dependency>
<!--模板引擎-->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>${velocity.version}</version>
</dependency>
2.添加配置文件
/resources/mybatis-plus.properties
#此处为本项目src所在路径(代码生成器输出路径),注意一定是当前项目所在的目录哟
OutputDir=D:/project/supplychain_api/src/main/java
#mapper.xml SQL映射文件目录
OutputDirXml=D:/project/supplychain_api/src/test/resources
#设置作者
author=smj
#自定义包路径
parent=com.zt
#数据库连接信息
mysql.driver=com.mysql.jdbc.Driver
mysql.url=jdbc:mysql://47.96.22.250:33066/ybt_saas?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false
mysql.user=dbsql
mysql.pwd=$027@mydbsql
3.添加测试类
/generator/GenteratorCode.java
public class GenteratorCode {
public static void main(String[] args) throws InterruptedException {
//用来获取mybatis-plus.properties文件的配置信息
final ResourceBundle rb = ResourceBundle.getBundle("mybatis-plus");
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir(rb.getString("OutputDir"));
gc.setFileOverride(true);
gc.setActiveRecord(true);
gc.setEnableCache(false);// XML 二级缓存
gc.setBaseResultMap(true);// XML ResultMap
gc.setBaseColumnList(true);// XML columList
gc.setAuthor(rb.getString("author"));
// 自定义文件命名,注意 %s 会自动填充表实体属性!
gc.setMapperName("%sMapper");
gc.setXmlName("%sMapper");
gc.setServiceName("I%sService");
gc.setServiceImplName("%sServiceImpl");
gc.setControllerName("%sController");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setDbType(DbType.MYSQL);
/*dsc.setTypeConvert(new MySqlTypeConvert(){
// 自定义数据库表字段类型转换【可选】
@Override
public DbColumnType processTypeConvert(String fieldType) {
System.out.println("转换类型:" + fieldType);
return super.processTypeConvert(fieldType);
}
});*/
dsc.setDriverName(rb.getString("mysql.driver"));
dsc.setUrl(rb.getString("mysql.url"));
dsc.setUsername(rb.getString("mysql.user"));
dsc.setPassword(rb.getString("mysql.pwd"));
mpg.setDataSource(dsc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
// strategy.setCapitalMode(true);// 全局大写命名 ORACLE 注意
//strategy.setTablePrefix(new String[] { "SYS_" });// 此处可以修改为您的表前缀
strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
strategy.setInclude(new String[] {"jf_order"}); // 需要生成的表
//strategy.setExclude(new String[]{"test"}); // 排除生成的表
mpg.setStrategy(strategy);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setParent(rb.getString("parent"));
// pc.setModuleName("tbldept");//模块名称,单独生成模块时使用!!!!!!!!!!!
pc.setController("controller");
pc.setService("service");
pc.setServiceImpl("service.impl");
pc.setEntity("entity");
pc.setMapper("mapper");
mpg.setPackageInfo(pc);
// 注入自定义配置,可以在 VM 中使用 cfg.abc 【可无】
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("abc", this.getConfig().getGlobalConfig().getAuthor() + "-rb");
this.setMap(map);
}
};
// 调整 xml 生成目录演示
List<FileOutConfig> focList = new ArrayList<FileOutConfig>();
focList.add(new FileOutConfig("/templates/mapper.xml.vm") {
@Override
public String outputFile(TableInfo tableInfo) {
return rb.getString("OutputDirXml")+ "/mybatis/mappers/" + tableInfo.getEntityName() + "Mapper.xml";
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
// 关闭默认 xml 生成,调整生成 至 根目录
TemplateConfig tc = new TemplateConfig();
tc.setXml(null);
mpg.setTemplate(tc);
// 执行生成
mpg.execute();
}
}
3.运行测试类
mysql逆向工程(mybatis plus)
标签:init mys 维护 add 自定义 nbsp 大写 return tis
本文系统来源:https://www.cnblogs.com/smj1990/p/11771721.html
内容总结
以上是互联网集市为您收集整理的mysql逆向工程(mybatis plus)全部内容,希望文章能够帮你解决mysql逆向工程(mybatis plus)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。