View Code
其中generatorConfig.xml的位置,大家根据实际情况自行调整
二、generatorConfig.xml配置文件
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE generatorConfiguration
3 PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
4 "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
5
6 <generatorConfiguration>
7 <classPathEntry
8 location="C:/Oracle/Middleware/wlserver_10.3/server/lib/ojdbc6.jar"/>
9 <context id="my" targetRuntime="MyBatis3">
10 <commentGenerator>
11 <property name="suppressDate" value="false"/>
12 <property name="suppressAllComments" value="true"/>
13 </commentGenerator>
14
15 <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
16 connectionURL="jdbc:oracle:thin:@172.20.16.***:1521:CARGO" userId="***"
17 password="***"/>
18
19 <javaModelGenerator targetPackage="ctas.test.entity"
20 targetProject="D:/yangjm/Code/CTAS/JAVAEE/CTAS2CCSP/src/main/java">
21 <property name="enableSubPackages" value="true"/>
22 <property name="trimStrings" value="true"/>
23 </javaModelGenerator>
24
25 <sqlMapGenerator targetPackage="ctas.test.entity.xml"
26 targetProject="D:/yangjm/Code/CTAS/JAVAEE/CTAS2CCSP/src/main/java">
27 <property name="enableSubPackages" value="true"/>
28 </sqlMapGenerator>
29
30 <javaClientGenerator targetPackage="ctas.test.mapper"
31 targetProject="D:/yangjm/Code/CTAS/JAVAEE/CTAS2CCSP/src/main/java" type="XMLMAPPER">
32 <property name="enableSubPackages" value="true"/>
33 </javaClientGenerator>
34
35 <!--<table tableName="T_FEE_AGTBILL" domainObjectName="FeeAgentBill"
36enableCountByExample="false" enableUpdateByExample="false"
37enableDeleteByExample="false" enableSelectByExample="false"
38selectByExampleQueryId="false"/>-->
39
40 <table tableName="CTAS_FEE_BASE" domainObjectName="FeeBase"
41enableCountByExample="false" enableUpdateByExample="false"
42enableDeleteByExample="false" enableSelectByExample="false"
43selectByExampleQueryId="false">
44 <!--<columnRenamingRule searchString="^D_"
45 replaceString=""/>-->
46 </table>
47
48 </context>
49 </generatorConfiguration>
你说的是修改表字段映射成实体类时,数据类型不一致问题吗?今天项目中遇到问题,看能否帮你。
使用mybatis-plus 代码生成器时,mysql 字段为 DateTime。映射实体类的属性类型为LocalDateTime,查询时显示字段不能映射上。才发现java Bean 字段不是Date。
修改代码生成器代码:
// 数据源配置DataSourceConfig dsc = new DataSourceConfig()
dsc.setTypeConvert(new MySqlTypeConvert() {//修改mysql datetime 生成实体类 date 类型
@Override
public DbColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) {
if ( fieldType.toLowerCase().contains( "datetime" ) ) {
return DbColumnType.DATE
}
return (DbColumnType) super.processTypeConvert(globalConfig, fieldType)
}
})
再次运行程序生成实体类:
问题解决:
zip包,然后自动下载下来
1.预先定义好模板
2.界面输入相关参数
3.解析模板生成代码并下载
最后放出源代码:
package com.et.controller.system.createcode
import java.util.ArrayList
import java.util.Date
import java.util.HashMap
import java.util.List
import java.util.Map
import javax.servlet.http.HttpServletResponse
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping
import com.et.controller.base.BaseController
import com.et.util.DelAllFile
import com.et.util.FileDownload
import com.et.util.FileZip
import com.et.util.Freemarker
import com.et.util.PageData
import com.et.util.PathUtil
/**
* 类名称:FreemarkerController
* 创建人:Harries
* 创建时间:2015年1月12日
* @version
*/
@Controller
@RequestMapping(value=”/createCode”)
public class CreateCodeController extends BaseController {
/**
* 生成代码
*/
@RequestMapping(value=”/proCode”)
public void proCode(HttpServletResponse response) throws Exception{
PageData pd = new PageData()
pd = this.getPageData()
/* ============================================================================================= */
String packageName = pd.getString(“packageName”)//包名 ========1
String objectName = pd.getString(“objectName”)//类名 ========2
String tabletop = pd.getString(“tabletop”)//表前缀 ========3
tabletop = null == tabletop?””:tabletop.toUpperCase()//表前缀转大写
String zindext = pd.getString(“zindex”)//属性总数
int zindex = 0
if(null != zindext &&!””.equals(zindext)){
zindex = Integer.parseInt(zindext)
}
List<String[]>fieldList = new ArrayList<String[]>()//属性集合 ========4
for(int i=0i<zindexi++){
fieldList.add(pd.getString(“field”+i).split(“,fh,”))//属性放到集合里面
}
Map<String,Object>root = new HashMap<String,Object>()//创建数据模型
root.put(“fieldList”, fieldList)
root.put(“packageName”, packageName)//包名
root.put(“objectName”, objectName)//类名
root.put(“objectNameLower”, objectName.toLowerCase())//类名(全小写)
root.put(“objectNameUpper”, objectName.toUpperCase())//类名(全大写)
root.put(“tabletop”, tabletop)//表前缀
root.put(“nowDate”, new Date())//当前日期
DelAllFile.delFolder(PathUtil.getClasspath()+”admin/ftl”)//生成代码前,先清空之前生成的代码
/* ============================================================================================= */
String filePath = “admin/ftl/code/”//存放路径
String ftlPath = “createCode”//ftl路径
/*生成controller*/
Freemarker.printFile(“controllerTemplate.ftl”, root, “controller/”+packageName+”/”+objectName.toLowerCase()+”/”+objectName+”Controller.java”, filePath, ftlPath)
/*生成service*/
Freemarker.printFile(“serviceTemplate.ftl”, root, “service/”+packageName+”/”+objectName.toLowerCase()+”/”+objectName+”Service.java”, filePath, ftlPath)
/*生成mybatis xml*/
Freemarker.printFile(“mapperMysqlTemplate.ftl”, root, “mybatis_mysql/”+packageName+”/”+objectName+”Mapper.xml”, filePath, ftlPath)
Freemarker.printFile(“mapperOracleTemplate.ftl”, root, “mybatis_oracle/”+packageName+”/”+objectName+”Mapper.xml”, filePath, ftlPath)
/*生成SQL脚本*/
Freemarker.printFile(“mysql_SQL_Template.ftl”, root, “mysql数据库脚本/”+tabletop+objectName.toUpperCase()+”.sql”, filePath, ftlPath)
Freemarker.printFile(“oracle_SQL_Template.ftl”, root, “oracle数据库脚本/”+tabletop+objectName.toUpperCase()+”.sql”, filePath, ftlPath)
/*生成jsp页面*/
Freemarker.printFile(“jsp_list_Template.ftl”, root, “jsp/”+packageName+”/”+objectName.toLowerCase()+”/”+objectName.toLowerCase()+”_list.jsp”, filePath, ftlPath)
Freemarker.printFile(“jsp_edit_Template.ftl”, root, “jsp/”+packageName+”/”+objectName.toLowerCase()+”/”+objectName.toLowerCase()+”_edit.jsp”, filePath, ftlPath)
/*生成说明文档*/
Freemarker.printFile(“docTemplate.ftl”, root, “说明.doc”, filePath, ftlPath)
//this.print(“oracle_SQL_Template.ftl”, root)控制台打印
/*生成的全部代码压缩成zip文件*/
FileZip.zip(PathUtil.getClasspath()+”admin/ftl/code”, PathUtil.getClasspath()+”admin/ftl/code.zip”)
/*下载代码*/
FileDownload.fileDownload(response, PathUtil.getClasspath()+”admin/ftl/code.zip”, “code.zip”)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)