日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

飞机票网上订票系统javabean+jsp+mysql

發(fā)布時(shí)間:2024/3/26 数据库 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 飞机票网上订票系统javabean+jsp+mysql 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.包含源程序,數(shù)據(jù)庫腳本。代碼和數(shù)據(jù)庫腳本都有詳細(xì)注釋。
2.課題設(shè)計(jì)僅供參考學(xué)習(xí)使用,可以在此基礎(chǔ)上進(jìn)行擴(kuò)展完善
開發(fā)環(huán)境:

?代碼已經(jīng)上傳github,下載地址:https://github.com/21503882/airplane-ticket
Eclipse ,MYSQL,JDK1.8,Tomcat 7
涉及技術(shù)點(diǎn):
MVC模式、SpringMvc、Mybatis、Spring、bootstrap、HTML、JavaScript、CSS、JQUERY、log4j、Ajax、maven等
系統(tǒng)采用Mybatis框架實(shí)現(xiàn)ORM對象關(guān)系映射,前臺JSP實(shí)現(xiàn),后臺springMvc映射,使用Spring框架進(jìn)行整合。適合學(xué)習(xí)J2EE的一段時(shí)間的熟手,代碼思路清晰,注解詳細(xì),數(shù)據(jù)庫用的是mysql5.1,服務(wù)器用的tomcat7,JDK版本1.8. 編程軟件Eclispe J2EE版本。是典型MVC架構(gòu),并且前后臺分離

主要功能界面:
??

?
下圖分別為:
新會員注冊——登錄——預(yù)定飛機(jī)票——查看預(yù)定信息
? ? ?

會員中心:


后臺管理員登錄:
?


4.1.1系統(tǒng)功能模塊的劃分
根據(jù)航空公司的需要,系統(tǒng)應(yīng)當(dāng)包含基本的功能有:用戶注冊、用戶登錄和管理員登錄,航班查看等。用戶則劃分為基本乘客和管理員兩大類,管理員還兼具有管理職能。功能模塊圖如下:

?

import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.sql.*;
import java.util.*;
import java.util.regex.Pattern;

/**
?* mybatisgen generate core.
?*
?* @author bleedfly.
?*/
public class MyBatisGenCore {
? ? private static String dbLocation = "db.config";

? ? /**
? ? ?* 根據(jù)表名獲取字段信息
? ? ?*
? ? ?* @param cn
? ? ?* @param table
? ? ?* @return
? ? ?* @throws Exception
? ? ?*/
? ? public static List<Map<String, String>> getColInfoList(Connection cn, String table) throws Exception {
? ? ? ? String sql = "select * from " + table + " where 1>2";
? ? ? ? Statement stmt = null;
? ? ? ? ResultSet rs = null;
? ? ? ? try {
? ? ? ? ? ? // 獲取數(shù)據(jù)庫元數(shù)據(jù)信息
? ? ? ? ? ? DatabaseMetaData dbmd = cn.getMetaData();
? ? ? ? ? ? ResultSet primaryKeys = dbmd.getPrimaryKeys(null, null, table);
? ? ? ? ? ? String pks =getstrPimaryKeys(primaryKeys);

? ? ? ? ? ? stmt = cn.createStatement();
? ? ? ? ? ? rs = stmt.executeQuery(sql);
? ? ? ? ? ? // 獲取結(jié)果集元數(shù)據(jù)信息
? ? ? ? ? ? ResultSetMetaData rsmd = rs.getMetaData();

? ? ? ? ? ? int num = rsmd.getColumnCount();
? ? ? ? ? ? Map<String, String> map;
? ? ? ? ? ? List<Map<String, String>> list = new ArrayList<Map<String, String>>();
? ? ? ? ? ? for (int i = 1; i <= num; i++) {
? ? ? ? ? ? ? ? map = new HashMap<String, String>();
? ? ? ? ? ? ? ? map.put(MyBatisGenConst.RSMD_COLUMN_NAME, rsmd.getColumnName(i));
? ? ? ? ? ? ? ? map.put(MyBatisGenConst.RSMD_COLUMN_CLASS_NAME, rsmd.getColumnClassName(i));
? ? ? ? ? ? ? ? map.put(MyBatisGenConst.RSMD_COLUMN_TYPE_NAME, rsmd.getColumnTypeName(i));
? ? ? ? ? ? ? ? map.put(MyBatisGenConst.RSMD_COLUMN_PRECISION, rsmd.getPrecision(i) + "");
? ? ? ? ? ? ? ? map.put(MyBatisGenConst.RSMD_COLUMN_SCALE, rsmd.getScale(i) + "");
? ? ? ? ? ? ? ? list.add(map);
? ? ? ? ? ? }
? ? ? ? ? ? //主鍵串放入list
? ? ? ? ? ? map = new HashedMap();
? ? ? ? ? ? map.put(MyBatisGenConst.RSMD_COLUMN_PRIMARY_KEY,pks);
? ? ? ? ? ? list.add(map);
? ? ? ? ? ? return list;
? ? ? ? } catch (Exception e) {
? ? ? ? ? ? throw new Exception(e + ",table=" + table, e);
? ? ? ? } finally {
? ? ? ? ? ? try {
? ? ? ? ? ? ? ? stmt.close();
? ? ? ? ? ? } catch (Exception e2) {
? ? ? ? ? ? ? ? e2.printStackTrace();
? ? ? ? ? ? }
? ? ? ? ? ? try {
? ? ? ? ? ? ? ? rs.close();
? ? ? ? ? ? } catch (Exception e2) {
? ? ? ? ? ? ? ? e2.printStackTrace();
? ? ? ? ? ? }
? ? ? ? }
? ? }

? ? /**
? ? ?* 獲取列信息。
? ? ?*
? ? ?* @param table
? ? ?* @return
? ? ?* @throws Exception
? ? ?*/
? ? public static List<Map<String, String>> getColInfoList(String table) throws Exception {
? ? ? ? Connection cn = getConnection();
? ? ? ? try {
? ? ? ? ? ? return getColInfoList(cn, table);
? ? ? ? } finally {
? ? ? ? ? ? try {
? ? ? ? ? ? ? ? cn.close();
? ? ? ? ? ? } catch (Exception e2) {
? ? ? ? ? ? ? ? e2.printStackTrace();
? ? ? ? ? ? }
? ? ? ? }
? ? }

? ? /**
? ? ?* 獲取參數(shù)列表
? ? ?*
? ? ?* @param colInfoList
? ? ?* @return
? ? ?* @throws Exception
? ? ?*/
? ? public static List<Map<String, String>> makeParamList(List<Map<String, String>> colInfoList) throws Exception {
? ? ? ? List<Map<String, String>> list = new ArrayList<Map<String, String>>();
? ? ? ? Map<String, String> map;
? ? ? ? int num = colInfoList.size();
? ? ? ? Map<String, String> mapNew;
? ? ? ? for (int i = 0; i < num; i++) {
? ? ? ? ? ? map = colInfoList.get(i);
? ? ? ? ? ? mapNew = new HashMap<String, String>();
? ? ? ? ? ? String columnName = map.get(MyBatisGenConst.RSMD_COLUMN_NAME);
? ? ? ? ? ? String columnClassName = map.get(MyBatisGenConst.RSMD_COLUMN_CLASS_NAME);
? ? ? ? ? ? String columnTypeName = map.get(MyBatisGenConst.RSMD_COLUMN_TYPE_NAME);
? ? ? ? ? ? String scaleStr = map.get(MyBatisGenConst.RSMD_COLUMN_SCALE);
? ? ? ? ? ? int scale = NumberUtils.toInt(scaleStr);
? ? ? ? ? ? String precisionStr = map.get(MyBatisGenConst.RSMD_COLUMN_PRECISION);
? ? ? ? ? ? int precision = NumberUtils.toInt(precisionStr);
? ? ? ? ? ? // mysql中的數(shù)據(jù)類型與java數(shù)據(jù)類型映射轉(zhuǎn)換
? ? ? ? ? ? String javaType = getJavaType(columnClassName, columnTypeName, scale, precision);
? ? ? ? ? ? String jdbcType = getJdbcType(columnClassName, columnTypeName);
? ? ? ? ? ? // 將有"_"的列名轉(zhuǎn)換成java中的駝峰命名規(guī)則
? ? ? ? ? ? String propName = getPropName(columnName);
? ? ? ? ? ? // 生成java實(shí)體類中屬性對應(yīng)的getter和setter方法名
? ? ? ? ? ? String setMethod = getSetMethod(propName);
? ? ? ? ? ? String getMethod = getGetMethod(propName);
? ? ? ? ? ? mapNew.put(MyBatisGenConst.VP_COLUMN_NAME, columnName.toLowerCase());
? ? ? ? ? ? mapNew.put(MyBatisGenConst.VP_PROP_NAME, propName);
? ? ? ? ? ? mapNew.put(MyBatisGenConst.VP_JAVA_TYPE, javaType);
? ? ? ? ? ? mapNew.put(MyBatisGenConst.VP_JDBC_TYPE, jdbcType);
? ? ? ? ? ? mapNew.put(MyBatisGenConst.VP_GET_METHOD, getMethod);
? ? ? ? ? ? mapNew.put(MyBatisGenConst.VP_SET_METHOD, setMethod);
? ? ? ? ? ? list.add(mapNew);
? ? ? ? }
? ? ? ? return list;
? ? }

? ? /**
? ? ?* 獲取字段的java類型
? ? ?*
? ? ?* @param columnClassName 字段類名
? ? ?* @param columnTypeName ?字段類型名稱
? ? ?* @param scale ? ? ? ? ? 精度 小數(shù)位數(shù)
? ? ?* @return
? ? ?*/
? ? public static String getJavaType(String columnClassName, String columnTypeName, int scale, int precision) {
? ? ? ? if (columnClassName.equals("java.sql.Timestamp")) {
? ? ? ? ? ? return "Date";
? ? ? ? }
? ? ? ? if (columnClassName.equals("java.lang.String")) {
? ? ? ? ? ? return "String";
? ? ? ? }
? ? ? ? if (columnTypeName.equals("DECIMAL") && scale < 1) {
? ? ? ? ? ? return "Long";
? ? ? ? }
? ? ? ? if (columnTypeName.equals("DECIMAL") && scale > 0) {
? ? ? ? ? ? return "java.math.BigDecimal";
? ? ? ? }
? ? ? ? if (columnTypeName.startsWith("BIGINT")) {
? ? ? ? ? ? return "Long";
? ? ? ? }
? ? ? ? if (columnTypeName.startsWith("INT")) {
? ? ? ? ? ? return "Integer";
? ? ? ? }
? ? ? ? if (columnTypeName.startsWith("TINYINT") && precision == 1) {
? ? ? ? ? ? return "Boolean";
? ? ? ? }
? ? ? ? if (columnTypeName.startsWith("TINYINT") && precision != 1) {
? ? ? ? ? ? return "Integer";
? ? ? ? }
? ? ? ? if (columnTypeName.startsWith("SMALLINT")) {
? ? ? ? ? ? return "Integer";
? ? ? ? }
? ? ? ? return columnClassName;
? ? }

? ? /**
? ? ?* 獲取jdbc類型
? ? ?*
? ? ?* @param columnClassName 字段類名
? ? ?* @param columnTypeName ?字段類型名稱
? ? ?* @return
? ? ?*/
? ? public static String getJdbcType(String columnClassName, String columnTypeName) {
? ? ? ? System.out.println(columnClassName+","+columnTypeName);
? ? ? ? if (columnClassName.equals("java.lang.String")) {
? ? ? ? ? ? return "VARCHAR";
? ? ? ? }
? ? ? ? if (columnClassName.startsWith("java.sql.")) {
? ? ? ? ? ? return "TIMESTAMP";
? ? ? ? }
? ? ? ? if (columnTypeName.startsWith("NUMBER")) {
? ? ? ? ? ? return "DECIMAL";
? ? ? ? }
? ? ? ? if (columnTypeName.startsWith("INT")) {
? ? ? ? ? ? return "INTEGER";
? ? ? ? }
? ? ? ? return columnTypeName;
? ? }

? ? /**
? ? ?* 根據(jù)表名獲取java類型
? ? ?*
? ? ?* @param tableName 表名
? ? ?* @return
? ? ?*/
? ? public static String getClassName(String tableName) {
? ? ? ? String t = tableName.toLowerCase();
? ? ? ? t = t.replace(MyBatisGenConst.TABLE_PREFIX, "");
? ? ? ? String[] arr = t.split("_");
? ? ? ? int num = arr.length;
? ? ? ? StringBuilder s = new StringBuilder();
? ? ? ? for (int i = 0; i < num; i++) {
? ? ? ? ? ? s.append(StringUtils.capitalize(arr[i]));
? ? ? ? }
? ? ? ? return s.toString();
? ? }

? ? /**
? ? ?* 根據(jù)字段名獲取java數(shù)據(jù)對象屬性名
? ? ?*
? ? ?* @param columnName 字段名
? ? ?* @return
? ? ?*/
? ? public static String getPropName(String columnName) {
? ? ? ? String t = columnName.toLowerCase();
? ? ? ? String[] arr = t.split("_");
? ? ? ? int num = arr.length;
? ? ? ? StringBuilder s = new StringBuilder();
? ? ? ? for (int i = 0; i < num; i++) {
? ? ? ? ? ? if (i > 0) {
? ? ? ? ? ? ? ? s.append(StringUtils.capitalize(arr[i]));// 首字母大寫
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? s.append(arr[i]);
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return s.toString();
? ? }

? ? public static String getSetMethod(String propName) {
? ? ? ? return "set" + StringUtils.capitalize(propName);
? ? }

? ? public static String getGetMethod(String propName) {
? ? ? ? return "get" + StringUtils.capitalize(propName);
? ? }

? ? public static String getColsStr(List<Map<String, String>> list) {
? ? ? ? int num = list.size();
? ? ? ? Map<String, String> map;
? ? ? ? String colName;
? ? ? ? StringBuilder stringBuilder = new StringBuilder();
? ? ? ? for (int i = 0; i < num; i++) {
? ? ? ? ? ? map = list.get(i);
? ? ? ? ? ? colName = map.get(MyBatisGenConst.VP_COLUMN_NAME);
? ? ? ? ? ? if (i > 0) {
? ? ? ? ? ? ? ? stringBuilder.append(",");
? ? ? ? ? ? }
? ? ? ? ? ? stringBuilder.append(colName);
? ? ? ? }
? ? ? ? return stringBuilder.toString();
? ? }

? ? public static String getstrPimaryKeys(ResultSet primaryKeys) throws SQLException {
? ? ? ? StringBuffer sb = new StringBuffer();
? ? ? ? String pks;
? ? ? ? while (primaryKeys.next()) {
? ? ? ? ? ? sb.append(primaryKeys.getString(MyBatisGenConst.COLUMN_NAME)).append(",");
? ? ? ? }
? ? ? ? pks = sb.toString();
? ? ? ? return StringUtils.isBlank(pks)?"":pks.substring(0,pks.length()-1);
? ? }

? ? /**
? ? ?* velocity模板合并
? ? ?*
? ? ?* @param template 模板字符串 如 hello,${name}
? ? ?* @param paramMap 參數(shù)
? ? ?* @return
? ? ?* @throws Exception
? ? ?*/
? ? public static String merge(String template, Map<String, Object> paramMap) throws Exception {
? ? ? ? VelocityContext vc = new VelocityContext(paramMap);
? ? ? ? StringWriter writer = new StringWriter();
? ? ? ? Velocity.evaluate(vc, writer, "mybatis_code_gen", template);
? ? ? ? return writer.getBuffer().toString();
? ? }

? ? /**
? ? ?* 獲取sqlmap 參數(shù)列表 去掉 主鍵 GMT_CREATE GMT_MODIFIED 字段
? ? ?*
? ? ?* @param paramList
? ? ?* @param pks
? ? ?* @return
? ? ?* @throws Exception
? ? ?*/
? ? public static List<Map<String, String>> getSqlmapParamList(List<Map<String, String>> paramList, String pks) throws Exception {
? ? ? ? List<Map<String, String>> list = new ArrayList<Map<String, String>>();
? ? ? ? Map<String, String> tmp;
? ? ? ? Map<String, String> map;
? ? ? ? int num = paramList.size();
? ? ? ? for (int i = 0; i < num; i++) {
? ? ? ? ? ? tmp = paramList.get(i);
? ? ? ? ? ? String columnName = tmp.get(MyBatisGenConst.VP_COLUMN_NAME);
? ? ? ? ? ? if (columnName.equalsIgnoreCase(pks)) {
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
? ? ? ? ? ? if (columnName.equalsIgnoreCase("GMT_CREATE")) {
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
? ? ? ? ? ? if (columnName.equalsIgnoreCase("GMT_MODIFIED")) {
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
? ? ? ? ? ? map = new HashMap<String, String>();
? ? ? ? ? ? map.putAll(tmp);
? ? ? ? ? ? list.add(map);
? ? ? ? }
? ? ? ? return list;
? ? }

? ? /**
? ? ?* 根據(jù)表名生成java數(shù)據(jù)對象類文件和sqlmap文件
? ? ?*
? ? ?* @param table 表名
? ? ?* @throws Exception
? ? ?*/
? ? public static void gen(String table) throws Exception {

? ? ? ? //TODO 拿出pkList
? ? ? ? // 先獲取表結(jié)構(gòu)信息,其中包含每個(gè)列的基本信息:如列名,類型,精度等信息,以map數(shù)據(jù)結(jié)構(gòu)保存
? ? ? ? List<Map<String, String>> colInfoList = getColInfoList(table);
? ? ? ? // 拿到主鍵
? ? ? ? String pks = colInfoList.remove(colInfoList.size() - 1).get(MyBatisGenConst.RSMD_COLUMN_PRIMARY_KEY);
? ? ? ? // 將屬性信息轉(zhuǎn)換成java數(shù)據(jù)結(jié)構(gòu)規(guī)則的形式
? ? ? ? List<Map<String, String>> paramList = makeParamList(colInfoList);

? ? ? ? boolean isSharding = Pattern.compile(MyBatisGenConst.SHARDING_SUFFIX_REG).matcher(table).find();
? ? ? ? if (isSharding) {
? ? ? ? ? ? // 去掉分庫分表后面的表后綴,如_0001
? ? ? ? ? ? table = table.replaceAll(MyBatisGenConst.SHARDING_SUFFIX_REG, "");
? ? ? ? }

? ? ? ? // 將"_"的表名轉(zhuǎn)換成java中對應(yīng)的實(shí)體類類型(首字母大寫,駝峰命名)
? ? ? ? String className = getClassName(table);

? ? ? ? String doTemplate = FileUtils.readFileToString(new File(MyBatisGenConst.DO_TEMPLATE), Charset.forName("UTF-8"));
? ? ? ? String queryTemplate = FileUtils.readFileToString(new File(MyBatisGenConst.QUERY_TEMPLATE), Charset.forName("UTF-8"));
? ? ? ? String sqlmapTemplate = FileUtils.readFileToString(new File(MyBatisGenConst.SQLMAP_TEMPLATE), Charset.forName("UTF-8"));
? ? ? ? String mapperTemplate = FileUtils.readFileToString(new File(MyBatisGenConst.MAPPER_TEMPLATE), Charset.forName("UTF-8"));
? ? ? ? String managerTemplate = FileUtils.readFileToString(new File(MyBatisGenConst.MANAGER_TEMPLATE), Charset.forName("UTF-8"));
? ? ? ? String managerImplTemplate = FileUtils.readFileToString(new File(MyBatisGenConst.MANAGER_IMPL_TEMPLATE), Charset.forName("UTF-8"));
? ? ? ? String sqlmapExtTemplate = FileUtils.readFileToString(new File(MyBatisGenConst.SQLMAP_EXT_TEMPLATE), Charset.forName("UTF-8"));
? ? ? ? String mapperExtTemplate = FileUtils.readFileToString(new File(MyBatisGenConst.MAPPER_EXT_TEMPLATE), Charset.forName("UTF-8"));

? ? ? ? Map<String, Object> param = new HashMap<String, Object>();

? ? ? ? param.put(MyBatisGenConst.VP_MAIN_PACKAGE, MyBatisGenConst.MAIN_PACKAGE);
? ? ? ? param.put(MyBatisGenConst.VP_DO_PACKAGE, MyBatisGenConst.DO_PACKAGE);
? ? ? ? param.put(MyBatisGenConst.VP_QUERY_PACKAGE, MyBatisGenConst.QUERY_PACKAGE);
? ? ? ? param.put(MyBatisGenConst.VP_MAPPER_PACKAGE, MyBatisGenConst.MAPPER_PACKAGE);
? ? ? ? param.put(MyBatisGenConst.VP_MANAGER_PACKAGE, MyBatisGenConst.MANAGER_PACKAGE);
? ? ? ? param.put(MyBatisGenConst.VP_MANAGER_IMPL_PACKAGE, MyBatisGenConst.MANAGER_IMPL_PACKAGE);
? ? ? ? param.put(MyBatisGenConst.VP_MAPPER_EXT_PACKAGE, MyBatisGenConst.MAPPER_EXT_PACKAGE);
? ? ? ? param.put(MyBatisGenConst.VP_CLASS_NAME, className);
? ? ? ? param.put(MyBatisGenConst.VP_MAPPER_PROPERTY_NAME, className.substring(0,1).toLowerCase()+className.substring(1)+MyBatisGenConst.MAPPER_EXT_SUFFIX);

? ? ? ? param.put(MyBatisGenConst.VP_LIST, paramList);
? ? ? ? param.put(MyBatisGenConst.VP_QUERY_PREFIX, MyBatisGenConst.QUERY_PREFIX);
? ? ? ? param.put(MyBatisGenConst.VP_DO_SUFFIX, MyBatisGenConst.DO_SUFFIX);
? ? ? ? param.put(MyBatisGenConst.VP_MAPPER_SUFFIX, MyBatisGenConst.MAPPER_SUFFIX);
? ? ? ? param.put(MyBatisGenConst.VP_MANAGER_SUFFIX, MyBatisGenConst.MANAGER_SUFFIX);
? ? ? ? param.put(MyBatisGenConst.VP_MANAGER_IMPL_SUFFIX, MyBatisGenConst.MANAGER_IMPL_SUFFIX);


? ? ? ? param.put(MyBatisGenConst.VP_MAPPER_EXT_SUFFIX, MyBatisGenConst.MAPPER_EXT_SUFFIX);

? ? ? ? String vpTableName = table.toLowerCase();
? ? ? ? if (isSharding) {
? ? ? ? ? ? vpTableName += "_$tabNum$";
? ? ? ? }

? ? ? ? param.put(MyBatisGenConst.VP_TABLE_NAME, vpTableName);
? ? ? ? param.put(MyBatisGenConst.VP_SERIAL_VERSION_UID, "" + (long) (Math.random() * 1000000000000000000L));

? ? ? ? param.put(MyBatisGenConst.VP_SERIAL_VERSION_UID2, "" + (long) (Math.random() * 1000000000000000000L));

? ? ? ? // param的信息量好大~
? ? ? ? String doResult = merge(doTemplate, param);

? ? ? ? // 獲取字段名不包含 id gmt_create gmt_modified TODO 去掉主鍵
? ? ? ? List<Map<String, String>> sqlmapParamList = getSqlmapParamList(paramList,pks);
? ? ? ? param.put(MyBatisGenConst.VP_LIST, sqlmapParamList);

? ? ? ? String colsWithoutCommColumns = getColsStr(sqlmapParamList);
? ? ? ? param.put(MyBatisGenConst.VP_COLS_WITHOUT_COMMON_COLUMNS, colsWithoutCommColumns);
? ? ? ? String cols = pks+"," + MyBatisGenConst.COMMON_COLUMN_STR + colsWithoutCommColumns;
? ? ? ? param.put(MyBatisGenConst.VP_COLS, cols);
? ? ? ? //TODO 這樣只支持 單個(gè)主鍵
? ? ? ? param.put(MyBatisGenConst.VP_PRIMARY_KEY, pks);
? ? ? ? param.put(MyBatisGenConst.VP_PROP_PRIMARY_KEY,getPropName(pks));
? ? ? ? //TODO param添加主鍵
? ? ? ? String sqlmapResult = merge(sqlmapTemplate, param);
? ? ? ? String mapperResult = merge(mapperTemplate, param);
? ? ? ? String managerResult = merge(managerTemplate, param);
? ? ? ? String managerImplResult = merge(managerImplTemplate, param);
? ? ? ? String queryResult = merge(queryTemplate, param);
? ? ? ? String mapperExtResult = merge(mapperExtTemplate, param);
? ? ? ? String sqlmapExtResult = merge(sqlmapExtTemplate, param);

? ? ? ? String doOutFilePath = MyBatisGenConst.MAPPER_DO_DIR + "/" + className + MyBatisGenConst.DO_SUFFIX + ".java";
? ? ? ? String queryOutFilePath = MyBatisGenConst.MAPPER_QUERY_DIR + "/" + className + MyBatisGenConst.QUERY_PREFIX + ".java";
? ? ? ? String sqlmapOutFilePath = MyBatisGenConst.MAPPER_XML_DIR + "/" + className + MyBatisGenConst.MAPPER_SUFFIX + ".xml";
? ? ? ? String mapperOutFilePath = MyBatisGenConst.MAPPER_JAVA_DIR + "/" + className + MyBatisGenConst.MAPPER_SUFFIX + ".java";
? ? ? ? String managerOutFilePath = MyBatisGenConst.MANAGER_JAVA_DIR + "/" + className + MyBatisGenConst.MANAGER_SUFFIX + ".java";
? ? ? ? String managerImplOutFilePath = MyBatisGenConst.MANAGER_IMPL_JAVA_DIR + "/" + className + MyBatisGenConst.MANAGER_IMPL_SUFFIX + ".java";
? ? ? ? String sqlmapExtOutFilePath = MyBatisGenConst.MAPPER_EXT_XML_DIR + "/" + className + MyBatisGenConst.MAPPER_EXT_SUFFIX + ".xml";
? ? ? ? String mapperExtOutFilePath = MyBatisGenConst.MAPPER_EXT_JAVA_DIR + "/" + className + MyBatisGenConst.MAPPER_EXT_SUFFIX + ".java";

? ? ? ? boolean success = new File(MyBatisGenConst.MAPPER_DO_DIR).mkdirs();
? ? ? ? if (!success) {
? ? ? ? ? ? System.out.println(String.format("mkdir %s error", MyBatisGenConst.MAPPER_DO_DIR));
? ? ? ? }
? ? ? ? success = new File(MyBatisGenConst.MAPPER_QUERY_DIR).mkdirs();
? ? ? ? if (!success) {
? ? ? ? ? ? System.out.println(String.format("mkdir %s error", MyBatisGenConst.MAPPER_QUERY_DIR));
? ? ? ? }

? ? ? ? success = new File(MyBatisGenConst.MANAGER_JAVA_DIR).mkdirs();
? ? ? ? if (!success) {
? ? ? ? ? ? System.out.println(String.format("mkdir %s error", MyBatisGenConst.MANAGER_JAVA_DIR));
? ? ? ? }

? ? ? ? success = new File(MyBatisGenConst.MANAGER_IMPL_JAVA_DIR).mkdirs();
? ? ? ? if (!success) {
? ? ? ? ? ? System.out.println(String.format("mkdir %s error", MyBatisGenConst.MANAGER_IMPL_JAVA_DIR));
? ? ? ? }

? ? ? ? success = new File(MyBatisGenConst.MAPPER_XML_DIR).mkdirs();
? ? ? ? if (!success) {
? ? ? ? ? ? System.out.println(String.format("mkdir %s error", MyBatisGenConst.MAPPER_XML_DIR));
? ? ? ? }
? ? ? ? success = new File(MyBatisGenConst.MAPPER_JAVA_DIR).mkdirs();
? ? ? ? if (!success) {
? ? ? ? ? ? System.out.println(String.format("mkdir %s error", MyBatisGenConst.MAPPER_JAVA_DIR));
? ? ? ? }
? ? ? ? success = new File(MyBatisGenConst.MAPPER_EXT_XML_DIR).mkdirs();
? ? ? ? if (!success) {
? ? ? ? ? ? System.out.println(String.format("mkdir %s error", MyBatisGenConst.MAPPER_EXT_XML_DIR));
? ? ? ? }
? ? ? ? success = new File(MyBatisGenConst.MAPPER_EXT_JAVA_DIR).mkdirs();
? ? ? ? if (!success) {
? ? ? ? ? ? System.out.println(String.format("mkdir %s error", MyBatisGenConst.MAPPER_EXT_JAVA_DIR));
? ? ? ? }

? ? ? ? File sqlmapOutFile = new File(sqlmapOutFilePath);
? ? ? ? if (!sqlmapOutFile.exists()) {
? ? ? ? ? ? success = sqlmapOutFile.createNewFile();
? ? ? ? ? ? if (!success) {
? ? ? ? ? ? ? ? System.out.println(String.format("createNewFile %s error", sqlmapOutFilePath));
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? File doOutFile = new File(doOutFilePath);
? ? ? ? if (!doOutFile.exists()) {
? ? ? ? ? ? success = doOutFile.createNewFile();
? ? ? ? ? ? if (!success) {
? ? ? ? ? ? ? ? System.out.println(String.format("createNewFile %s error", doOutFilePath));
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? File mapperOutFile = new File(mapperOutFilePath);
? ? ? ? if (!mapperOutFile.exists()) {
? ? ? ? ? ? success = mapperOutFile.createNewFile();
? ? ? ? ? ? if (!success) {
? ? ? ? ? ? ? ? System.out.println(String.format("createNewFile %s error", mapperOutFilePath));
? ? ? ? ? ? }
? ? ? ? }


? ? ? ? File queryOutFile = new File(queryOutFilePath);
? ? ? ? if (!queryOutFile.exists()) {
? ? ? ? ? ? success = queryOutFile.createNewFile();
? ? ? ? ? ? if (!success) {
? ? ? ? ? ? ? ? System.out.println(String.format("createNewFile %s error", queryOutFilePath));
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? FileUtils.writeStringToFile(sqlmapOutFile, sqlmapResult, Charset.forName("UTF-8"));
? ? ? ? FileUtils.writeStringToFile(doOutFile, doResult, Charset.forName("UTF-8"));
? ? ? ? FileUtils.writeStringToFile(queryOutFile, queryResult, Charset.forName("UTF-8"));
? ? ? ? FileUtils.writeStringToFile(mapperOutFile, mapperResult, Charset.forName("UTF-8"));


? ? ? ? File mapperExtOutFile = new File(mapperExtOutFilePath);
? ? ? ? if (!mapperExtOutFile.exists()) {
? ? ? ? ? ? try{
? ? ? ? ? ? ? ? mapperExtOutFile.createNewFile();
? ? ? ? ? ? }catch (IOException e){
? ? ? ? ? ? ? ? System.out.print("create file error");
? ? ? ? ? ? }
? ? ? ? ? ? FileUtils.writeStringToFile(mapperExtOutFile, mapperExtResult, Charset.forName("UTF-8"));
? ? ? ? }

? ? ? ? File sqlmapExtOutFile = new File(sqlmapExtOutFilePath);
? ? ? ? if (!sqlmapExtOutFile.exists()) {
? ? ? ? ? ? boolean created = sqlmapExtOutFile.createNewFile();
? ? ? ? ? ? if(created){
? ? ? ? ? ? ? ? FileUtils.writeStringToFile(sqlmapExtOutFile, sqlmapExtResult, Charset.forName("UTF-8"));
? ? ? ? ? ? }
? ? ? ? }


? ? ? ? File managerOutFile = new File(managerOutFilePath);
? ? ? ? if (!managerOutFile.exists()) {
? ? ? ? ? ? success = managerOutFile.createNewFile();
? ? ? ? ? ? if (!success) {
? ? ? ? ? ? ? ? System.out.println(String.format("createNewFile %s error", managerOutFilePath));
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? FileUtils.writeStringToFile(managerOutFile, managerResult, Charset.forName("UTF-8"));
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? File managerImplOutFile = new File(managerImplOutFilePath);
? ? ? ? if (!managerImplOutFile.exists()) {
? ? ? ? ? ? success = managerImplOutFile.createNewFile();
? ? ? ? ? ? if (!success) {
? ? ? ? ? ? ? ? System.out.println(String.format("createNewFile %s error", managerImplOutFilePath));
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? FileUtils.writeStringToFile(managerImplOutFile, managerImplResult, Charset.forName("UTF-8"));
? ? ? ? ? ? }
? ? ? ? }
? ? }

? ? /**
? ? ?* 獲取數(shù)據(jù)庫連接
? ? ?*
? ? ?* @return
? ? ?* @throws ClassNotFoundException
? ? ?* @throws SQLException
? ? ?* @throws FileNotFoundException
? ? ?* @throws IOException
? ? ?*/
? ? private static Connection getConnection() throws ClassNotFoundException, SQLException,
? ? ? ? ? ? IOException {
? ? ? ? Properties prop = new Properties();
? ? ? ? prop.load(ClassLoader.getSystemResourceAsStream(dbLocation));
? ? ? ? Class.forName(prop.getProperty("driver"));
? ? ? ? String url = prop.getProperty("url");
? ? ? ? String user = prop.getProperty("user");
? ? ? ? String psw = prop.getProperty("pwd");
? ? ? ? return DriverManager.getConnection(url, user, psw);
? ? }

? ? /**
? ? ?* 批量生成java數(shù)據(jù)對象類文件和sqlmap文件
? ? ?*
? ? ?* @param tables 表 多個(gè)表用逗號分隔 table1,table2,table3
? ? ?* @throws Exception
? ? ?*/
? ? public static void batchGen(List<String> tables, String location) throws Exception {
? ? ? ? dbLocation = location;
? ? ? ? System.out.println("table numbers: " + tables.size());
? ? ? ? Connection cn = getConnection();
? ? ? ? try {
? ? ? ? ? ? for (String table : tables) {
? ? ? ? ? ? ? ? MyBatisGenCore.gen(table.trim());
? ? ? ? ? ? ? ? System.out.println(table.trim() + " done");
? ? ? ? ? ? }
? ? ? ? } finally {
? ? ? ? ? ? try {
? ? ? ? ? ? ? ? cn.close();
? ? ? ? ? ? } catch (Exception e) {
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
?代碼已經(jīng)上傳github,下載地址:https://github.com/21503882/airplane-ticket

總結(jié)

以上是生活随笔為你收集整理的飞机票网上订票系统javabean+jsp+mysql的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。