├── .gitignore ├── README.md ├── classes ├── log4j.xml └── log4jdbc.log4j2.properties ├── config.xml ├── img.png ├── pom.xml └── src ├── Main.java └── kr └── co └── itpaper └── mysqldocument ├── dao ├── MyBatisConnectionFactory.java └── mapper │ └── TableMapper.xml ├── model ├── TableName.java └── TableStruct.java └── service ├── TableService.java └── impl └── TableServiceImpl.java /.gitignore: -------------------------------------------------------------------------------- 1 | # 컴파일 결과물 제외 2 | *.com 3 | *.class 4 | *.dll 5 | *.exe 6 | *.o 7 | *.so 8 | 9 | # 로그파일 제외 10 | *.log 11 | 12 | # 운영체제에서 만드는 시스템 파일들 제외 13 | .DS_Store 14 | .DS_Store? 15 | ._* 16 | .Spotlight-V100 17 | .Trashes 18 | ehthumbs.db 19 | Thumbs.db 20 | config.xml 21 | 22 | # 프로젝트정보 파일 제외 23 | .metadata 24 | bin/ 25 | tmp/ 26 | *.tmp 27 | *.bak 28 | *.swp 29 | *~.nib 30 | local.properties 31 | .settings/ 32 | .loadpath 33 | .recommenders 34 | .project 35 | .externalToolBuilders/ 36 | *.launch 37 | .classpath 38 | .factorypath 39 | .buildpath 40 | .target 41 | /build/ 42 | target/ 43 | 44 | # Spring 팀프로젝트 충돌 방지 45 | MANIFEST.MF 46 | pom.properties 47 | target/ 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MySQL 테이블 명세서 생성 프로그램 2 | 이 프로그램은 메가스터디IT아카데미(신촌)에서 이광호 강사가 진행하는 훈련과정에 참여하는 수강생의 포트폴리오 활동에 도움이 되고자 작성되었습니다. 3 | MySQL의 테이블 구조를 조회하여 엑셀로 명세서를 저장해주는 프로그램 입니다. 프로그램 UI는 구성하지 않았습니다. 4 | 5 | - 저작도구: Eclipse 6 | - 사용언어: JAVA 7 | 8 | ## 사용방법 9 | 10 | 이클립스에서 프로젝트를 import한 후, config.xml 파일의 데이터베이스 접속 정보를 수정하고 바로 실행하면 됩니다. 11 | 12 | ```xml 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | ``` 21 | 22 | ## 실행 결과 산출물 예시 23 | 24 | ![Alt text](img.png) 25 | 26 | ## 사용된 라이브러리 27 | - https://github.com/virtuald/curvesapi 28 | - MySQL Connector java : https://dev.mysql.com/downloads/connector/j/3.0.html 29 | - MyBatis3 : http://www.mybatis.org/mybatis-3/ko/ 30 | - Apache Log4j2 : https://logging.apache.org/log4j/2.x/ 31 | - Apache POI Library : https://poi.apache.org/ 32 | - Apache XML Beans : https://xmlbeans.apache.org/ 33 | -------------------------------------------------------------------------------- /classes/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /classes/log4jdbc.log4j2.properties: -------------------------------------------------------------------------------- 1 | log4jdbc.auto.load.popular.drivers=false 2 | log4jdbc.drivers=com.mysql.cj.jdbc.Driver 3 | log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator 4 | log4jdbc.dump.sql.maxlinelength=0 5 | 6 | log4jdbc.debug.stack.prefix=sql 7 | log4jdbc.sqltiming.warn.threshold=0 8 | log4jdbc.sqltiming.error.threshold=0 9 | log4jdbc.dump.booleanastruefalse=false 10 | log4jdbc.dump.fulldebugstacktrace=false 11 | log4jdbc.statement.warn=false 12 | log4jdbc.dump.sql.select=true 13 | log4jdbc.dump.sql.insert=true 14 | log4jdbc.dump.sql.update=true 15 | log4jdbc.dump.sql.delete=true 16 | log4jdbc.dump.sql.create=true 17 | log4jdbc.dump.sql.addsemicolon=false 18 | log4jdbc.trim.sql=true 19 | log4jdbc.trim.sql.extrablanklines=true 20 | log4jdbc.suppress.generated.keys.exception=false -------------------------------------------------------------------------------- /config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leekh4232/mysql-table-document-creator/2231c0687ca4f863d9812a9bcef28c1eed166c81/img.png -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | mysql-table-document-creator 5 | mysql-table-document-creator 6 | 0.0.1-SNAPSHOT 7 | 8 | 1.8 9 | 1.6.6 10 | 11 | 12 | src 13 | 14 | 15 | src 16 | 17 | **/*.java 18 | 19 | 20 | 21 | 22 | 23 | maven-compiler-plugin 24 | 3.8.0 25 | 26 | 1.8 27 | 1.8 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | mysql 38 | mysql-connector-java 39 | 8.0.18 40 | 41 | 42 | 43 | 44 | 45 | org.mybatis 46 | mybatis 47 | 3.5.6 48 | 49 | 50 | 51 | 52 | com.github.virtuald 53 | curvesapi 54 | 1.06 55 | 56 | 57 | 58 | 59 | org.apache.xmlbeans 60 | xmlbeans 61 | 3.1.0 62 | 63 | 64 | 65 | 66 | org.apache.poi 67 | poi 68 | 4.1.1 69 | 70 | 71 | 72 | 73 | org.apache.poi 74 | poi-excelant 75 | 4.1.1 76 | 77 | 78 | 79 | 80 | org.apache.poi 81 | poi-ooxml 82 | 4.1.1 83 | 84 | 85 | 86 | 87 | org.apache.poi 88 | poi-ooxml-schemas 89 | 4.1.1 90 | 91 | 92 | 93 | 94 | org.apache.poi 95 | poi-scratchpad 96 | 4.1.1 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /src/Main.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.FileOutputStream; 3 | import java.io.IOException; 4 | import java.util.List; 5 | 6 | import javax.swing.JFileChooser; 7 | import javax.swing.JOptionPane; 8 | 9 | import org.apache.ibatis.session.SqlSession; 10 | import org.apache.poi.ss.usermodel.BorderStyle; 11 | import org.apache.poi.ss.usermodel.FillPatternType; 12 | import org.apache.poi.ss.usermodel.HorizontalAlignment; 13 | import org.apache.poi.ss.util.CellRangeAddress; 14 | import org.apache.poi.xssf.usermodel.XSSFCell; 15 | import org.apache.poi.xssf.usermodel.XSSFCellStyle; 16 | import org.apache.poi.xssf.usermodel.XSSFColor; 17 | import org.apache.poi.xssf.usermodel.XSSFFont; 18 | import org.apache.poi.xssf.usermodel.XSSFRow; 19 | import org.apache.poi.xssf.usermodel.XSSFSheet; 20 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 21 | 22 | import kr.co.itpaper.mysqldocument.dao.MyBatisConnectionFactory; 23 | import kr.co.itpaper.mysqldocument.model.TableName; 24 | import kr.co.itpaper.mysqldocument.model.TableStruct; 25 | import kr.co.itpaper.mysqldocument.service.TableService; 26 | import kr.co.itpaper.mysqldocument.service.impl.TableServiceImpl; 27 | 28 | public class Main { 29 | @SuppressWarnings("deprecation") 30 | public static void main(String[] args) { 31 | 32 | // parent component of the dialog 33 | JFileChooser fileChooser = new JFileChooser(); 34 | fileChooser.setDialogTitle("파일이 저장될 경로를 지정하세요."); 35 | 36 | int userSelection = fileChooser.showSaveDialog(null); 37 | String saveFileName = null; 38 | 39 | if (userSelection == JFileChooser.APPROVE_OPTION) { 40 | File fileToSave = fileChooser.getSelectedFile(); 41 | saveFileName = fileToSave.getAbsolutePath(); 42 | } else { 43 | return; 44 | } 45 | 46 | if (saveFileName.lastIndexOf(".xlsx") == -1) { 47 | saveFileName += ".xlsx"; 48 | } 49 | 50 | SqlSession sqlSession = MyBatisConnectionFactory.getSqlSession(); 51 | 52 | TableService tableService = new TableServiceImpl(sqlSession); 53 | 54 | List table = null; // 테이블 목록 55 | 56 | try { 57 | table = tableService.selectTableList(); 58 | 59 | for (int i = 0; i < table.size(); i++) { 60 | TableName tableItem = table.get(i); 61 | // 테이블 목록 수 만큼 구조 조회 SQL 호출 62 | tableItem.setStruct(tableService.selectTableStruct(tableItem.getTableName())); 63 | } 64 | } catch (Exception e) { 65 | JOptionPane.showMessageDialog(null, e.getLocalizedMessage(), "확인", JOptionPane.ERROR_MESSAGE); 66 | e.printStackTrace(); 67 | sqlSession.close(); 68 | return; 69 | } finally { 70 | sqlSession.close(); 71 | } 72 | 73 | // ----------- 74 | 75 | // 1차로 workbook을 생성 76 | XSSFWorkbook workbook = new XSSFWorkbook(); 77 | 78 | // 해더부분셀에 스타일을 주기위한 인스턴스 생성 79 | XSSFCellStyle headerStyle = workbook.createCellStyle(); 80 | headerStyle.setAlignment(HorizontalAlignment.CENTER); // 스타일인스턴스의 속성 81 | headerStyle.setFillForegroundColor(new XSSFColor(new java.awt.Color(255, 255, 0))); 82 | headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); 83 | headerStyle.setBorderRight(BorderStyle.THIN); // 테두리 설정 84 | headerStyle.setBorderLeft(BorderStyle.THIN); 85 | headerStyle.setBorderTop(BorderStyle.THIN); 86 | headerStyle.setBorderBottom(BorderStyle.THIN); 87 | XSSFFont font = workbook.createFont(); // 폰트 조정 인스턴스 생성 88 | font.setBold(true); 89 | font.setFontHeightInPoints((short) 16); 90 | headerStyle.setFont(font); 91 | 92 | // 가운데 정렬과 얇은 테두리를 위한 스타일 인스턴스 생성 93 | XSSFCellStyle cellStyle0 = workbook.createCellStyle(); 94 | cellStyle0.setAlignment(HorizontalAlignment.CENTER); 95 | cellStyle0.setBorderRight(BorderStyle.THIN); 96 | cellStyle0.setBorderLeft(BorderStyle.THIN); 97 | cellStyle0.setBorderTop(BorderStyle.THIN); 98 | cellStyle0.setBorderBottom(BorderStyle.THIN); 99 | XSSFFont font0 = workbook.createFont(); // 폰트 조정 인스턴스 생성 100 | font0.setFontHeightInPoints((short) 14); 101 | cellStyle0.setFont(font0); 102 | 103 | // 얇은 테두리를 위한 스타일 인스턴스 생성 104 | XSSFCellStyle cellStyle1 = workbook.createCellStyle(); 105 | cellStyle1.setAlignment(HorizontalAlignment.LEFT); 106 | cellStyle1.setBorderRight(BorderStyle.THIN); 107 | cellStyle1.setBorderLeft(BorderStyle.THIN); 108 | cellStyle1.setBorderTop(BorderStyle.THIN); 109 | cellStyle1.setBorderBottom(BorderStyle.THIN); 110 | XSSFFont font1 = workbook.createFont(); // 폰트 조정 인스턴스 생성 111 | font1.setFontHeightInPoints((short) 14); 112 | cellStyle1.setFont(font1); 113 | 114 | XSSFRow row = null; 115 | XSSFCell cell = null; 116 | 117 | // 2차는 sheet생성 118 | XSSFSheet sheet = workbook.createSheet("테이블명세서"); 119 | 120 | // 셀별 널비 정하기 헤더 그리기 121 | sheet.setColumnWidth((short) 0, (short) 2000); 122 | sheet.setColumnWidth((short) 1, (short) 5000); 123 | sheet.setColumnWidth((short) 2, (short) 4000); 124 | sheet.setColumnWidth((short) 3, (short) 3000); 125 | sheet.setColumnWidth((short) 4, (short) 3000); 126 | sheet.setColumnWidth((short) 5, (short) 5000); 127 | sheet.setColumnWidth((short) 6, (short) 10000); 128 | 129 | sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 1)); 130 | sheet.addMergedRegion(new CellRangeAddress(0, 0, 2, 6)); 131 | sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 1)); 132 | sheet.addMergedRegion(new CellRangeAddress(1, 1, 2, 6)); 133 | 134 | // 시트에 타이틀 행을 하나 생성한다.(i 값이 0이면 첫번째 줄에 해당) 135 | int k = 0; 136 | 137 | for (int i = 0; i < table.size(); i++) { 138 | TableName name = table.get(i); 139 | 140 | row = sheet.createRow((short) k++); 141 | cell = row.createCell(0); 142 | cell.setCellValue("TableName"); 143 | cell.setCellStyle(headerStyle); 144 | 145 | cell = row.createCell(1); 146 | cell.setCellStyle(headerStyle); 147 | 148 | cell = row.createCell(2); 149 | cell.setCellValue(name.getTableName().trim()); 150 | cell.setCellStyle(cellStyle1); 151 | 152 | cell = row.createCell(3); 153 | cell.setCellStyle(cellStyle1); 154 | cell = row.createCell(4); 155 | cell.setCellStyle(cellStyle1); 156 | cell = row.createCell(5); 157 | cell.setCellStyle(cellStyle1); 158 | cell = row.createCell(6); 159 | cell.setCellStyle(cellStyle1); 160 | 161 | row = sheet.createRow((short) k++); 162 | cell = row.createCell(0); 163 | cell.setCellValue("Description"); 164 | cell.setCellStyle(headerStyle); 165 | 166 | cell = row.createCell(1); 167 | cell.setCellStyle(headerStyle); 168 | 169 | cell = row.createCell(2); 170 | cell.setCellValue(name.getComment().trim()); 171 | cell.setCellStyle(cellStyle1); 172 | 173 | cell = row.createCell(3); 174 | cell.setCellStyle(cellStyle1); 175 | cell = row.createCell(4); 176 | cell.setCellStyle(cellStyle1); 177 | cell = row.createCell(5); 178 | cell.setCellStyle(cellStyle1); 179 | cell = row.createCell(6); 180 | cell.setCellStyle(cellStyle1); 181 | 182 | row = sheet.createRow((short) k++); 183 | 184 | cell = row.createCell(0); 185 | cell.setCellValue("No"); 186 | cell.setCellStyle(headerStyle); 187 | 188 | cell = row.createCell(1); 189 | cell.setCellValue("FieldName"); 190 | cell.setCellStyle(headerStyle); 191 | 192 | cell = row.createCell(2); 193 | cell.setCellValue("DataType"); 194 | cell.setCellStyle(headerStyle); 195 | 196 | cell = row.createCell(3); 197 | cell.setCellValue("Null"); 198 | cell.setCellStyle(headerStyle); 199 | 200 | cell = row.createCell(4); 201 | cell.setCellValue("Key"); 202 | cell.setCellStyle(headerStyle); 203 | 204 | cell = row.createCell(5); 205 | cell.setCellValue("Extra"); 206 | cell.setCellStyle(headerStyle); 207 | 208 | cell = row.createCell(6); 209 | cell.setCellValue("Comment"); 210 | cell.setCellStyle(headerStyle); 211 | 212 | List structList = name.getStruct(); 213 | 214 | for (int j = 0; j < structList.size(); j++, k++) { 215 | // 시트에 하나의 행을 생성한다(i 값이 0이면 첫번째 줄에 해당) 216 | row = sheet.createRow((short) k); 217 | 218 | TableStruct struct = structList.get(j); 219 | 220 | // 생성된 row에 컬럼을 생성한다 221 | int x = 0; 222 | cell = row.createCell(x++); 223 | cell.setCellValue(struct.getId()); 224 | cell.setCellStyle(cellStyle0); 225 | 226 | cell = row.createCell(x++); 227 | cell.setCellValue(struct.getFieldName().trim()); 228 | cell.setCellStyle(cellStyle1); 229 | 230 | cell = row.createCell(x++); 231 | cell.setCellValue(struct.getDataType().trim()); 232 | cell.setCellStyle(cellStyle0); 233 | 234 | cell = row.createCell(x++); 235 | cell.setCellValue(struct.getIsNull().trim()); 236 | cell.setCellStyle(cellStyle0); 237 | 238 | cell = row.createCell(x++); 239 | cell.setCellValue(struct.getKey().trim()); 240 | cell.setCellStyle(cellStyle0); 241 | 242 | cell = row.createCell(x++); 243 | cell.setCellValue(struct.getExtra().trim()); 244 | cell.setCellStyle(cellStyle0); 245 | 246 | cell = row.createCell(x++); 247 | cell.setCellValue(struct.getComment().replace("\\n", " ").trim()); 248 | cell.setCellStyle(cellStyle1); 249 | } 250 | 251 | // 테이블간 빈 줄 삽입 252 | row = sheet.createRow((short) k++); 253 | cell = row.createCell(1); 254 | cell = row.createCell(2); 255 | cell = row.createCell(3); 256 | cell = row.createCell(4); 257 | cell = row.createCell(5); 258 | cell = row.createCell(6); 259 | row = sheet.createRow((short) k++); 260 | cell = row.createCell(1); 261 | cell = row.createCell(2); 262 | cell = row.createCell(3); 263 | cell = row.createCell(4); 264 | cell = row.createCell(5); 265 | cell = row.createCell(6); 266 | } 267 | 268 | FileOutputStream fos = null; 269 | try { 270 | fos = new FileOutputStream(saveFileName); 271 | // 파일을 쓴다 272 | workbook.write(fos); 273 | } catch (Exception e) { 274 | JOptionPane.showMessageDialog(null, e.getLocalizedMessage(), "확인", JOptionPane.ERROR_MESSAGE); 275 | e.printStackTrace(); 276 | return; 277 | } finally { 278 | if (workbook != null) { 279 | try { 280 | workbook.close(); 281 | } catch (IOException e) { 282 | // TODO Auto-generated catch block 283 | e.printStackTrace(); 284 | } 285 | } 286 | 287 | if (fos != null) { 288 | try { 289 | fos.close(); 290 | } catch (IOException e) { 291 | JOptionPane.showMessageDialog(null, e.getLocalizedMessage(), "확인", JOptionPane.ERROR_MESSAGE); 292 | e.printStackTrace(); 293 | return; 294 | } 295 | } 296 | } 297 | 298 | JOptionPane.showMessageDialog(null, saveFileName + " 경로에 엑셀파일이 저장되었습니다.", "확인", JOptionPane.INFORMATION_MESSAGE); 299 | } 300 | } 301 | -------------------------------------------------------------------------------- /src/kr/co/itpaper/mysqldocument/dao/MyBatisConnectionFactory.java: -------------------------------------------------------------------------------- 1 | package kr.co.itpaper.mysqldocument.dao; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.io.FileReader; 5 | import java.io.Reader; 6 | 7 | import org.apache.ibatis.session.SqlSession; 8 | import org.apache.ibatis.session.SqlSessionFactory; 9 | import org.apache.ibatis.session.SqlSessionFactoryBuilder; 10 | 11 | public class MyBatisConnectionFactory { 12 | /** 데이터베이스 접속 객체 */ 13 | private static SqlSessionFactory sqlSessionFactory; 14 | 15 | /** XML에 명시된 접속 정보를 읽어들인다. */ 16 | static { 17 | try { 18 | 19 | // 접속 정보를 명시하고 있는 XML의 경로 읽기 20 | Reader reader = new FileReader(System.getProperty("user.dir") + "/config.xml"); 21 | 22 | if (sqlSessionFactory == null) { 23 | sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); 24 | } 25 | } catch (FileNotFoundException fileNotFoundException) { 26 | fileNotFoundException.printStackTrace(); 27 | } 28 | } 29 | 30 | /** 데이터베이스 접속 객체를 리턴한다. */ 31 | public static SqlSession getSqlSession() { 32 | return sqlSessionFactory.openSession(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/kr/co/itpaper/mysqldocument/dao/mapper/TableMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 44 | 45 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/kr/co/itpaper/mysqldocument/model/TableName.java: -------------------------------------------------------------------------------- 1 | package kr.co.itpaper.mysqldocument.model; 2 | 3 | import java.util.List; 4 | 5 | public class TableName { 6 | // 테이블이름 7 | private String tableName; 8 | // 테이블 주석 9 | private String comment; 10 | // 테이블 구조 11 | private List struct; 12 | 13 | public String getTableName() { 14 | return tableName; 15 | } 16 | 17 | public void setTableName(String tableName) { 18 | this.tableName = tableName; 19 | } 20 | 21 | public String getComment() { 22 | return comment; 23 | } 24 | 25 | public void setComment(String comment) { 26 | this.comment = comment; 27 | } 28 | 29 | public List getStruct() { 30 | return struct; 31 | } 32 | 33 | public void setStruct(List struct) { 34 | this.struct = struct; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "TableName [tableName=" + tableName + ", comment=" + comment + ", struct=" + struct + "]"; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/kr/co/itpaper/mysqldocument/model/TableStruct.java: -------------------------------------------------------------------------------- 1 | package kr.co.itpaper.mysqldocument.model; 2 | 3 | public class TableStruct { 4 | // 일련번호 5 | private int id; 6 | // 컬럼명 7 | private String fieldName; 8 | // 데이터 타입 9 | private String dataType; 10 | // 널 허용 여부 11 | private String isNull; 12 | // 제약조건 13 | private String key; 14 | // 기타 속성 15 | private String extra; 16 | // 기본값 17 | private String defaultValue; 18 | // 주석 19 | private String comment; 20 | 21 | public int getId() { 22 | return id; 23 | } 24 | 25 | public void setId(int id) { 26 | this.id = id; 27 | } 28 | 29 | public String getFieldName() { 30 | return fieldName; 31 | } 32 | 33 | public void setFieldName(String fieldName) { 34 | this.fieldName = fieldName; 35 | } 36 | 37 | public String getDataType() { 38 | return dataType; 39 | } 40 | 41 | public void setDataType(String dataType) { 42 | this.dataType = dataType; 43 | } 44 | 45 | public String getIsNull() { 46 | return isNull; 47 | } 48 | 49 | public void setIsNull(String isNull) { 50 | this.isNull = isNull; 51 | } 52 | 53 | public String getKey() { 54 | return key; 55 | } 56 | 57 | public void setKey(String key) { 58 | this.key = key; 59 | } 60 | 61 | public String getExtra() { 62 | return extra; 63 | } 64 | 65 | public void setExtra(String extra) { 66 | this.extra = extra; 67 | } 68 | 69 | public String getDefaultValue() { 70 | return defaultValue; 71 | } 72 | 73 | public void setDefaultValue(String defaultValue) { 74 | this.defaultValue = defaultValue; 75 | } 76 | 77 | public String getComment() { 78 | return comment; 79 | } 80 | 81 | public void setComment(String comment) { 82 | this.comment = comment; 83 | } 84 | 85 | @Override 86 | public String toString() { 87 | return "TableDesc [id=" + id + ", fieldName=" + fieldName + ", dataType=" + dataType + ", isNull=" + isNull 88 | + ", key=" + key + ", extra=" + extra + ", defaultValue=" + defaultValue + ", comment=" + comment + "]"; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/kr/co/itpaper/mysqldocument/service/TableService.java: -------------------------------------------------------------------------------- 1 | package kr.co.itpaper.mysqldocument.service; 2 | 3 | import java.util.List; 4 | 5 | import kr.co.itpaper.mysqldocument.model.TableName; 6 | import kr.co.itpaper.mysqldocument.model.TableStruct; 7 | 8 | public interface TableService { 9 | 10 | /** 11 | * 테이블 목록을 리턴한다. 12 | * @return 13 | * @throws Exception 14 | */ 15 | public List selectTableList() throws Exception; 16 | 17 | /** 18 | * 주어진 테이블의 구조를 조회한다. 19 | * @param tableName - 테이블이름 20 | * @return 21 | * @throws Exception 22 | */ 23 | public List selectTableStruct(String tableName) throws Exception; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/kr/co/itpaper/mysqldocument/service/impl/TableServiceImpl.java: -------------------------------------------------------------------------------- 1 | package kr.co.itpaper.mysqldocument.service.impl; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.session.SqlSession; 6 | import kr.co.itpaper.mysqldocument.model.TableName; 7 | import kr.co.itpaper.mysqldocument.model.TableStruct; 8 | import kr.co.itpaper.mysqldocument.service.TableService; 9 | 10 | public class TableServiceImpl implements TableService { 11 | 12 | /** MyBatis */ 13 | // --> import org.apache.ibatis.session.SqlSession 14 | SqlSession sqlSession; 15 | 16 | /** 생성자를 통한 객체 생성 */ 17 | public TableServiceImpl(SqlSession sqlSession) { 18 | this.sqlSession = sqlSession; 19 | } 20 | 21 | @Override 22 | public List selectTableList() throws Exception { 23 | List result = null; 24 | 25 | try { 26 | result = sqlSession.selectList("TableMapper.selectTableList"); 27 | if (result == null) { 28 | throw new NullPointerException(); 29 | } 30 | } catch (NullPointerException e) { 31 | throw new Exception("조회된 테이블 목록이 없습니다."); 32 | } catch (Exception e) { 33 | e.printStackTrace(); 34 | System.out.println(e.getLocalizedMessage()); 35 | throw new Exception("테이블 목록 조회에 실패했습니다."); 36 | } 37 | 38 | return result; 39 | } 40 | 41 | @Override 42 | public List selectTableStruct(String tableName) throws Exception { 43 | List result = null; 44 | 45 | try { 46 | result = sqlSession.selectList("TableMapper.selectTableStruct", tableName); 47 | if (result == null) { 48 | throw new NullPointerException(); 49 | } 50 | } catch (NullPointerException e) { 51 | throw new Exception(tableName + "(은)는 존재하지 않는 테이블입니다."); 52 | } catch (Exception e) { 53 | System.out.println(e.getLocalizedMessage()); 54 | throw new Exception(tableName + "테이블 구조 조회에 실패했습니다."); 55 | } 56 | 57 | return result; 58 | } 59 | 60 | } 61 | --------------------------------------------------------------------------------