package cn.witsky.quota.base.createsource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
/**
*
* <p>ClassName:CreateSource</p>
* <p>Description:生成代码神器
* 开发文件生成工具
* 使用方法:文件夹自己建 为了防止覆盖已有的文件,如果文件已存在程序终止该程序。</p>
* 该模块数据库连接在类里面配。完全独立于系统工程
* @author wangxiaobo
* @date 2015-11-11
*/
public class CreateSource {
//表名(必须小写) 如果大写出现问题后果自找
private static String tableName = "t_smb_msisdn".toLowerCase();
private static String url="jdbc:oracle:thin:@192.168.150.233:1521/ddcx";
private static String user="ddcx";
private static String password="czty_ddcx";
/////////////////////////////////////////////////////
//方法
private static String constant_insert = "insert";
private static String constant_delete = "delete";
private static String constant_update = "update";
private static String constant_getById = "getById";
private static String constant_findAll= "findAll";
//生成文件存放的位置,该文件夹要选建好后才能进行。
private static String objectPath = "main.java.cn.witsky.quota.base.createsource.temp";
public static void main(String[] args) throws Exception {
//Oracle数据库链接拿到相关字段信息
GetSqlFileds getSqlFileds = new GetSqlFileds();
//生成实体xml配置文件
String sqlFileds = getSqlFileds.getSqlWithFileds(url,user,password,tableName);
generateXml(tableName,sqlFileds);
//生成实体类
List<String> sqlFiledsComList = getSqlFileds.getSqlWithFiledsCom(url,user,password,tableName);
generateObj(tableName,sqlFiledsComList);
//生成dao文件
generateDao();
//生成service文件
//generateService();
//生成Controller文件
//generateController();
//生成配置文件
//generateConfig();
}
/**
* 生成配置文件
* @throws IOException
*/
public static void generateConfig() throws IOException {
//实体xml配置文件路径为
String fileName = getFilePath()+ "\\" +getObjectName() + "Config.xml";
System.out.println("配置文件路径为:" + fileName);
File file = new File(fileName);
if (!file.exists()) {
if (file.createNewFile()) {
System.out.println("配置文件创建成功!");
} else {
System.out.println("配置文件创建失败!");
return;
}
} else {
System.out.println("程序终止,配置文件已经存在");
return;
}
FileOutputStream out = new FileOutputStream(file, true);
StringBuffer sb = new StringBuffer();
sb.append("<!-- sqlmap.xml -->");
sb.append("\n");
sb.append(" <sqlMap resource=\""+objectPath.replace(".", "/")+"/entity/"+getObjectName()+".xml\" />");
sb.append("\n");
sb.append("\n");
sb.append("<!-- applicationContext.xml -->");
sb.append("\n");
sb.append(" <bean id=\""+toBartoUpperCase(tableName)+"Dao\" class=\""+objectPath+".dao."+getObjectName()+"Dao\"/>");
out.write(sb.toString().getBytes("utf-8"));
out.close();
System.out.println("配置文件生成结束!");
}
/**
* 生成Controller文件
* @throws IOException
*/
public static void generateController() throws IOException {
//实体xml配置文件路径为
String fileName = getFilePath()+ "\\" +getObjectName() + "Controller.java";
System.out.println("Controller文件路径为:" + fileName);
File file = new File(fileName);
if (!file.exists()) {
if (file.createNewFile()) {
System.out.println("Controller文件创建成功!");
} else {
System.out.println("Controller文件创建失败!");
return;
}
} else {
System.out.println("程序终止,Controller文件已经存在");
return;
}
FileOutputStream out = new FileOutputStream(file, true);
StringBuffer sb = new StringBuffer();
sb.append("package "+objectPath+".controller;");
sb.append("\n");
sb.append("\n");
sb.append("@Controller");
sb.append("\n");
sb.append("@RequestMapping(\"不要这么懒自己改一下吧/"+toLowerCaseFirstOne(getObjectName())+"/\")");
sb.append("\n");
sb.append("public class "+getObjectName()+"Controller extends BaseController{");
sb.append("\n");
sb.append(" @Autowired");
sb.append("\n");
sb.append(" private "+getObjectName()+"Service "+toLowerCaseFirstOne(getObjectName())+"Service;");
sb.append("\n");
sb.append("\n");
sb.append("}");
out.write(sb.toString().getBytes("utf-8"));
out.close();
System.out.println("Dao文件生成结束!");
}
/**
* 生成Service文件
* @throws IOException
*/
public static void generateService() throws IOException {
//实体xml配置文件路径为
String fileName = getFilePath()+ "\\" +getObjectName() + "Service.java";
System.out.println("Service文件路径为:" + fileName);
File file = new File(fileName);
if (!file.exists()) {
if (file.createNewFile()) {
System.out.println("Service文件创建成功!");
} else {
System.out.println("Service文件创建失败!");
return;
}
} else {
System.out.println("程序终止,Service文件已经存在");
return;
}
FileOutputStream out = new FileOutputStream(file, true);
StringBuffer sb = new StringBuffer();
sb.append("package "+objectPath+".service;");
sb.append("\n");
sb.append("\n");
sb.append("@Service");
sb.append("\n");
sb.append("public class "+getObjectName()+"Service extends BaseService<"+getObjectName()+">{");
sb.append("\n");
sb.append("\n");
sb.append("}");
out.write(sb.toString().getBytes("utf-8"));
out.close();
System.out.println("Dao文件生成结束!");
}
/**
* 生成Dao文件
* @throws IOException
*/
public static void generateDao() throws IOException {
//实体xml配置文件路径为
String fileName = getFilePath()+ "\\" +getObjectName() + "Dao.java";
System.out.println("Dao文件路径为:" + fileName);
File file = new File(fileName);
if (!file.exists()) {
if (file.createNewFile()) {
System.out.println("Dao文件创建成功!");
} else {
System.out.println("Dao文件创建失败!");
return;
}
} else {
System.out.println("程序终止,Dao文件已经存在");
return;
}
FileOutputStream out = new FileOutputStream(file, true);
StringBuffer sb = new StringBuffer();
sb.append("package "+objectPath+".dao;");
sb.append("\n");
sb.append("\n");
sb.append("@Repository");
sb.append("\n");
sb.append("public class "+getObjectName()+"Dao extends BaseDao<"+getObjectName()+">{");
sb.append("\n");
sb.append("\n");
sb.append("}");
out.write(sb.toString().getBytes("utf-8"));
out.close();
System.out.println("Dao文件生成结束!");
}
/**
* 生成实体对象文件
* @throws IOException
*/
public static void generateObj(String tableName,List<String> sqlFiledsComList) throws IOException {
//实体xml配置文件路径为
String fileName = getFilePath()+ "\\" +getObjectName() + ".java";
System.out.println("实体对象文件路径为:" + fileName);
File file = new File(fileName);
if (!file.exists()) {
if (file.createNewFile()) {
System.out.println("实体对象文件创建成功!");
} else {
System.out.println("实体对象文件创建失败!");
return;
}
} else {
System.out.println("程序终止,实体对象已经存在");
return;
}
FileOutputStream out = new FileOutputStream(file, true);
StringBuffer sb = new StringBuffer();
sb.append("package "+objectPath+".entity;");
sb.append("\n");
sb.append("\n");
sb.append("public class "+getObjectName()+" extends BaseEntity implements java.io.Serializable {");
sb.append("\n");
for(String sqlFi
没有合适的资源?快使用搜索试试~ 我知道了~
springboot +mybatis+oracle 配置多个数据源,配置两个数据库信息
共108个文件
xml:85个
java:20个
properties:2个
需积分: 50 83 下载量 132 浏览量
2019-12-25
13:41:10
上传
评论 2
收藏 68KB RAR 举报
温馨提示
springboot +mybatis+oracle 配置多个数据源,配置两个数据库信息
资源推荐
资源详情
资源评论
收起资源包目录
springboot +mybatis+oracle 配置多个数据源,配置两个数据库信息 (108个子文件)
smb-ddcx-quota.iml 9KB
CreateSource.java 17KB
Tools.java 16KB
FileUtil.java 13KB
GetSqlFileds.java 6KB
WorkController.java 6KB
BaseDao.java 6KB
BaseService.java 4KB
Constants.java 4KB
Application.java 3KB
DataSourceConfig1.java 3KB
WorkService.java 3KB
MyX509TrustManager.java 2KB
DataSourceConfig2.java 2KB
Cache.java 1KB
SmbMsisdn.java 1KB
Base.java 655B
SmbMsisdnMapper2.java 533B
SmbMsisdnMapper1.java 533B
Config.java 347B
CityIdQuota.java 316B
application.properties 3KB
version.properties 30B
workspace.xml 32KB
SmbMsisdn.xml 5KB
SmbMsisdn.xml 5KB
pom.xml 4KB
logback-spring.xml 1008B
misc.xml 916B
Maven__org_springframework_boot_spring_boot_starter_data_redis_1_5_2_RELEASE.xml 769B
Maven__org_springframework_boot_spring_boot_test_autoconfigure_1_5_2_RELEASE.xml 769B
Maven__org_springframework_boot_spring_boot_starter_logging_1_5_2_RELEASE.xml 748B
Maven__org_springframework_boot_spring_boot_starter_tomcat_1_5_2_RELEASE.xml 741B
Maven__org_springframework_boot_spring_boot_autoconfigure_1_5_2_RELEASE.xml 734B
Maven__org_mybatis_spring_boot_mybatis_spring_boot_autoconfigure_1_3_0.xml 730B
Maven__org_springframework_boot_spring_boot_starter_test_1_5_2_RELEASE.xml 727B
Maven__org_springframework_boot_spring_boot_starter_jdbc_1_5_2_RELEASE.xml 727B
Maven__org_springframework_boot_spring_boot_starter_web_1_5_2_RELEASE.xml 720B
Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml 700B
Maven__org_springframework_data_spring_data_keyvalue_1_2_1_RELEASE.xml 699B
Maven__org_springframework_data_spring_data_commons_1_13_1_RELEASE.xml 699B
Maven__org_springframework_spring_context_support_4_3_7_RELEASE.xml 693B
Maven__org_springframework_boot_spring_boot_starter_1_5_2_RELEASE.xml 692B
Maven__org_mybatis_spring_boot_mybatis_spring_boot_starter_1_3_0.xml 688B
Maven__org_springframework_data_spring_data_redis_1_8_1_RELEASE.xml 678B
Maven__org_springframework_boot_spring_boot_test_1_5_2_RELEASE.xml 671B
Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_5_11.xml 660B
Maven__org_springframework_spring_expression_4_3_7_RELEASE.xml 658B
Maven__org_springframework_retry_spring_retry_1_2_0_RELEASE.xml 647B
Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml 644B
compiler.xml 640B
Maven__org_springframework_spring_context_4_3_7_RELEASE.xml 637B
Maven__org_springframework_boot_spring_boot_1_5_2_RELEASE.xml 636B
Maven__org_hibernate_hibernate_validator_5_3_4_Final.xml 634B
Maven__org_springframework_spring_webmvc_4_3_7_RELEASE.xml 630B
Maven__org_apache_tomcat_embed_tomcat_embed_core_8_5_11.xml 625B
Maven__com_fasterxml_jackson_core_jackson_databind_2_8_7.xml 623B
Maven__org_springframework_spring_beans_4_3_7_RELEASE.xml 623B
Maven__org_springframework_spring_core_4_3_7_RELEASE.xml 616B
Maven__org_springframework_spring_test_4_3_7_RELEASE.xml 616B
Maven__org_springframework_spring_jdbc_4_3_7_RELEASE.xml 616B
Maven__org_apache_tomcat_embed_tomcat_embed_el_8_5_11.xml 611B
Maven__javax_validation_validation_api_1_1_0_Final.xml 611B
Maven__org_springframework_spring_aop_4_3_7_RELEASE.xml 609B
Maven__org_springframework_spring_oxm_4_3_7_RELEASE.xml 609B
Maven__org_springframework_spring_web_4_3_7_RELEASE.xml 609B
Maven__org_jboss_logging_jboss_logging_3_3_0_Final.xml 608B
Maven__org_springframework_spring_tx_4_3_7_RELEASE.xml 602B
Maven__com_fasterxml_jackson_core_jackson_core_2_8_7.xml 595B
Maven__commons_httpclient_commons_httpclient_3_1.xml 591B
Maven__org_apache_httpcomponents_httpclient_4_5_1.xml 577B
Maven__ch_qos_logback_logback_classic_1_1_11.xml 575B
Maven__commons_logging_commons_logging_1_0_4.xml 572B
Maven__org_apache_commons_commons_pool2_2_4_2.xml 570B
Maven__org_apache_httpcomponents_httpcore_4_4_6.xml 563B
Maven__org_slf4j_log4j_over_slf4j_1_7_24.xml 562B
Maven__org_apache_tomcat_tomcat_jdbc_8_5_11.xml 559B
Maven__org_apache_tomcat_tomcat_juli_8_5_11.xml 559B
Maven__ch_qos_logback_logback_core_1_1_11.xml 554B
Maven__org_hamcrest_hamcrest_library_1_3.xml 553B
Maven__org_mockito_mockito_core_1_10_19.xml 549B
Maven__org_mybatis_mybatis_spring_1_3_1.xml 549B
Maven__org_slf4j_jcl_over_slf4j_1_7_24.xml 548B
Maven__com_jayway_jsonpath_json_path_2_2_0.xml 546B
mybatis-config.xml 545B
Maven__commons_codec_commons_codec_1_10.xml 543B
Maven__net_minidev_accessors_smart_1_1.xml 542B
Maven__org_skyscreamer_jsonassert_1_4_0.xml 537B
Maven__org_assertj_assertj_core_2_6_0.xml 535B
Maven__org_slf4j_jul_to_slf4j_1_7_24.xml 534B
Maven__org_hamcrest_hamcrest_core_1_3.xml 532B
Maven__org_projectlombok_lombok_1_16_16.xml 531B
Maven__com_fasterxml_classmate_1_3_3.xml 522B
Maven__net_minidev_json_smart_2_2_1.xml 521B
Maven__com_alibaba_fastjson_1_1_41.xml 514B
Maven__org_slf4j_slf4j_api_1_7_24.xml 513B
Maven__org_objenesis_objenesis_2_1.xml 508B
Maven__org_mybatis_mybatis_3_4_4.xml 500B
Maven__com_google_guava_guava_19_0.xml 499B
Maven__org_yaml_snakeyaml_1_17.xml 495B
共 108 条
- 1
- 2
资源评论
码java的秃头阿姨
- 粉丝: 107
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功