使用工具:PowerDesign16.5、Navicat11.2.7、eclipse mars1、jetty。
詳細步驟:
1、使用PD做表結構
2、使用Navicat建數據庫表
3、配置數據庫連接
4、逆向工程代碼
5、代碼整合到項目中
6、后臺用戶中心添加功能模塊
7、項目本地運行
8、測試增刪改查功能
1、使用PD做表結構
2、雙擊表結構>prieview,將創建表語句復制粘貼到Navicat上的查詢>新建查詢>查詢編輯器>運行。
3、在com.sendinfo.tms.code項目下的com.sendinfo.code中創建一個config.properties,設置url。
jdbc.type=mysql
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.200.104:3306/tms_scenic?useUnicode=true&characterEncoding=utf-8
jdbc.username=tms
jdbc.password=Tms.2017
4、在com.sendinfo.tms.code項目下的com.sendinfo.code中創建一個EasyuiMain,
1)配置項
Map<String, Object> config = new HashMap<String, Object>();
2)配置基本包路徑
config.put("basepkg", "com.sendinfo.biz.resource");
3)配置WEB資源路徑
config.put("catalog", "resource");
4)日期替換
config.put("date", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
5)代碼寫入磁盤路徑
String rootPath = "E:\workspace\com.sendinfo.tms.code\codegen";
6)數據庫catalog
String catalog = "";
7)配置數據庫schema,Oracle數據庫的用戶名
String schema = "tms_scenic";
8)配置數據表名稱,多個以逗號隔開,支持Like查詢
String tableName = "traffic_info,exhibi_info";
9)任務名稱,取值:all(所有)、entity(只生成實體)、java(只生成Java代碼)、page(只生成頁面)、settle(結算系統)
String taskName = "easyui";
10)代碼生成
// 代碼生成
String location = "classpath:com/sendinfo/code/applicationContext.xml";
ApplicationContext context = new ClassPathXmlApplicationContext(location);
DatabaseFactory databaseFactory = (DatabaseFactory) context.getBean("databaseFactory");
DatabaseWapper database = databaseFactory.readDatabaseWapper(catalog.toUpperCase(), schema.toUpperCase(),
tableName.toUpperCase());
System.out.println("Tables: " + Arrays.asList(database.getTableNames()));
CodeService service = (CodeService) context.getBean("codeService");
List<CodeFile> filelist = service.gencode(database, taskName, config);
writeCodeFile(rootPath, filelist);//寫文件到硬盤
5、對EasyuiMain run as>java application,完成。
6、再去硬盤取出各個文件放到項目中對應的位置
6.1com\sendinfo\biz\resource下有:
--action>xxxxAction.java
--dao
custom>xxxxCustom.xml
impl>xxxxDaoImpl.java
mapper>xxxxMapper.xml
xxxxDao.java
--entity>xxxx.java
--service
impl>xxxxServiceImpl.java
>xxxxService.java
6.2resourece>每個表對應3個ftl文件,分別是add、edit、list,文件粘貼到sendinfo-tms-resource下的webapp.WEB-INF.ftl.resource中。
6.3struts>xxxAction.xml,把里邊的代碼粘貼到sendinfo-tms-resource下的resource.struts中的struts-resource.xml。
7、jetty:run 運行項目,然后在用戶中心>系統管理中,
1)權限管理>旅游資源管理,添加,如
名稱:公路交通資源
唯一編碼:traffic
URL:/resource/trafficinfo/list.htm
排序:8
2)角色管理>權限配置>在地理資源中勾選新添加的資源。