Skip to content

Commit

Permalink
修复切换数据库问题
Browse files Browse the repository at this point in the history
  • Loading branch information
dolyw committed Jun 25, 2019
1 parent eb077d6 commit d740efc
Show file tree
Hide file tree
Showing 8 changed files with 413 additions and 25 deletions.
16 changes: 15 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,25 @@
<version>1.9.21</version>
</dependency>

<!-- Mysql-Connector -->
<!-- Sql-Connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--<dependency>
<groupId>oracle.jdbc</groupId>
<artifactId>ojdbc6</artifactId>
<version>0.0.1</version>
</dependency>-->
<!--<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>

<!-- Mybatis -->
<dependency>
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/example/config/DataBaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ public class DataBaseConfig {
@Bean
@Primary
public GeneratorDao getGeneratorDao() {
String str = DataBaseEnum.MYSQL.getValue();
if(driver.indexOf(DataBaseEnum.MYSQL.getValue()) > 0) {
if(driver.indexOf(DataBaseEnum.MYSQL.getValue()) >= 0) {
return mySqlGeneratorDao;
} else if (driver.indexOf(DataBaseEnum.ORACLE.getValue()) > 0) {
} else if (driver.indexOf(DataBaseEnum.ORACLE.getValue()) >= 0) {
return oracleGeneratorDao;
} else if (driver.indexOf(DataBaseEnum.POSTGRESQL.getValue()) > 0) {
} else if (driver.indexOf(DataBaseEnum.POSTGRESQL.getValue()) >= 0) {
return postgreSqlGeneratorDao;
} else if (driver.indexOf(DataBaseEnum.SQLSERVER.getValue()) > 0) {
} else if (driver.indexOf(DataBaseEnum.SQLSERVER.getValue()) >= 0) {
return sqlServerGeneratorDao;
}
return null;
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ spring:
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
# validationQuery: select 'x'
validation-query: SELECT 1 from dual
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
Expand Down
37 changes: 19 additions & 18 deletions src/main/resources/config/generator.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ jdbc_catalog=
jdbc_schema=

# 数据源配置(Oracle)
# jdbc_driver=oracle.jdbc.OracleDriver
# jdbc_url=jdbc:oracle:thin:@47.XX.XX.XX:XXXX:XXX
# jdbc_username=system
# jdbc_password=123456
# jdbc_catalog=
# jdbc_schema=
# jdbc_driver=oracle.jdbc.OracleDriver
# jdbc_url=jdbc:oracle:thin:@XXX.XX.XX.XXX:XXXX/XXXX
# jdbc_username=XXX
# jdbc_password=XXX
# jdbc_catalog=
# jdbc_schema=

# 数据源配置(SqlServer)
# jdbc_driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
# jdbc_url=jdbc:sqlserver://192.168.XX.XX:XXXX;DatabaseName=XXX
# jdbc_username=sa
# jdbc_password=123456
# jdbc_catalog=
# jdbc_schema=
# jdbc_driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
# jdbc_url=jdbc:sqlserver://192.168.XX.XX:XXXX;DatabaseName=XXX
# jdbc_username=sa
# jdbc_password=123456
# jdbc_catalog=
# jdbc_schema=

# 数据源配置(PostgreSql)
# jdbc_driver=org.postgresql.Driver
# jdbc_url=jdbc:postgresql://192.168.XX.XX:XXXX/XXX
# jdbc_username=postgres
# jdbc_password=123456
# jdbc_catalog=
# jdbc_schema=
# jdbc_driver=org.postgresql.Driver
# jdbc_url=jdbc:postgresql://192.168.XX.XX:XXXX/XXX
# jdbc_username=postgres
# jdbc_password=123456
# jdbc_catalog=
# jdbc_schema=

# 代码生成的文件输出路径,可配置绝对路径或者当前项目相对路径
outRoot=E:/work/outRoot
Expand All @@ -53,6 +53,7 @@ namespace=jsp
modulepackage=generator
# 可以继续添加属性名属性值,对应模板代码
# XXXXX=XXXXX
moduleName=test

# 数据库列名大小写 U:大写 L:小写,不配置默认小写
column.sqlName.caseSize=L
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<#include "/macro.include">
<#assign className = table.className>
<#assign classNameLower = className?uncap_first>
import http from '@/utils/httpRequest'

export const baseURL = process.env.NODE_ENV !== 'production' && process.env.OPEN_PROXY ? '/proxyApi/' : window.SITE_CONFIG.baseUrl

/**
* 列表查询
* @param {*} searchForm
*/
export function list (searchForm) {
return http({
url: baseURL + '/${moduleName}/${classNameLower}',
method: 'get',
params: searchForm
})
}

/**
* 根据Id查询
* @param {*} id
*/
export function findById (id) {
return http({
url: baseURL + '/${moduleName}/${classNameLower}/' + id,
method: 'get'
})
}

/**
* 新增
* @param {*} data
*/
export function add (data) {
return http({
url: baseURL + '/${moduleName}/${classNameLower}',
method: 'post',
data
})
}

/**
* 修改
* @param {*} data
*/
export function update (data) {
return http({
url: baseURL + '/${moduleName}/${classNameLower}',
method: 'put',
data
})
}

/**
* 删除
* @param {*} id
*/
export function delById (id) {
return http({
url: baseURL + '/${moduleName}/${classNameLower}/' + id,
method: 'delete'
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<#include "/macro.include">
<#assign className = table.className>
<#assign classNameLower = className?uncap_first>
<template>
<div>
<!-- 查询表单 -->
<el-form :inline="true" :model="searchForm" label-width="100px" size="small">

<#list table.columns as column>
<el-form-item label="${column.columnAlias!}">
<el-input v-model.trim="searchForm.${column.columnNameLower}" placeholder="请输入${column.columnAlias!}" clearable />
</el-form-item>
</#list>

<el-row type="flex">
<el-form-item>
<el-button type="primary" v-if="isAuth('${moduleName}:${classNameLower}:list')" icon="el-icon-search" @click="list(searchForm)">查询</el-button>
<el-button type="primary" v-if="isAuth('${moduleName}:${classNameLower}:add')" icon="el-icon-plus" @click="preById(null)">新增</el-button>
</el-form-item>
</el-row>

</el-form>

<!-- 数据表格 -->
<el-table :data="tableData" v-loading="tableLoading" border style="width: 100%">

<#list table.columns as column>
<el-table-column prop="${column.columnNameLower}" label="${column.columnAlias!}" align="center" min-width="100" show-overflow-tooltip />
</#list>

<el-table-column label="操作" align="center" fixed="right" min-width="100">
<template slot-scope="scope">
<el-button type="text" v-if="isAuth('${moduleName}:${classNameLower}:update')" @click="preById(scope.row.<#list table.columns as column><#if column.pk>${column.columnNameLower}</#if></#list>)">编辑</el-button>
<el-button type="text" v-if="isAuth('${moduleName}:${classNameLower}:delete')" @click="delById(scope.row.<#list table.columns as column><#if column.pk>${column.columnNameLower}</#if></#list>)">删除</el-button>
</template>
</el-table-column>

</el-table>

<div align="right" style="margin-top:10px;">
<el-pagination
:current-page="searchForm.page"
:page-sizes="[20, 40, 60, 80]"
:page-size="searchForm.rows"
:total="totalCount"
layout="total, sizes, prev, pager, next, jumper"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"/>
</div>

<!-- 弹窗 -->
<edit ref="edit" @refreshTableData="list(searchForm)"></edit>
</div>
</template>

<script>
import Edit from './${classNameLower}Edit'
import * as ${classNameLower} from '@/api/${moduleName}/${classNameLower}'

export default {
name: '${className}',
data () {
return {
// 表格加载条控制
tableLoading: false,
// Table数据
tableData: [],
// Table数据总条数
totalCount: 0,
// 查询表单属性
searchForm: {
// 当前页
page: 1,
// 每页条数
rows: 20,
<#list table.columns as column>
'${column.columnNameLower}': null<#if column_has_next>,</#if>
</#list>
}
}
},
components: {
Edit
},
// 启动时就执行
mounted: function () {

},
// 获取活动窗口
activated () {
// 列表查询
this.list(this.searchForm)
},
methods: {
// 每页条数改变
handleSizeChange: function (rows) {
this.searchForm.rows = rows
// 刷新列表
this.list(this.searchForm)
},
// 当前页数改变
handleCurrentChange: function (page) {
this.searchForm.page = page
// 刷新列表
this.list(this.searchForm)
},
// 列表查询
list: function (searchForm) {
// 加载显示
this.tableLoading = true
${classNameLower}.list(searchForm).then(response => {
const data = response.data.data
this.tableData = data.data
this.totalCount = data.count
// 加载完成
this.tableLoading = false
})
},
// 调用子组件的preById方法
preById: function (<#list table.columns as column><#if column.pk>${column.columnNameLower}</#if></#list>) {
// this.$nextTick Dom渲染完执行
/* this.$nextTick(() => {
this.$refs.edit.preById(<#list table.columns as column><#if column.pk>${column.columnNameLower}</#if></#list>)
}) */
this.$refs.edit.preById(<#list table.columns as column><#if column.pk>${column.columnNameLower}</#if></#list>)
},
// 删除
delById: function (<#list table.columns as column><#if column.pk>${column.columnNameLower}</#if></#list>) {
this.$confirm('是否确定删除?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// 确定执行删除
${classNameLower}.delById(<#list table.columns as column><#if column.pk>${column.columnNameLower}</#if></#list>).then(response => {
const data = response.data
this.$message({
type: 'success',
message: data.msg
})
// 刷新列表
this.list(this.searchForm)
})
}).catch(() => {

})
}
}
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
Loading

0 comments on commit d740efc

Please sign in to comment.