최근에 나는 최대 절전 모드와 유사하게 Mybatis를 배우고 있으며, Mybatis는 또한 쉽고 빠른 개발을 위해 코드 (매핑, XML, Pojo)를 직접 생성 할 수있는 역 엔지니어링을 보유하고 있습니다. Mybatis-Generator-Core-1.3.2.jar 패키지를 사용합니다. 여기 MySQL 데이터베이스를 사용하고 있습니다.
1. MyBatis-Generator-Core-1.3.2.jar 및 MySQL-Connector-Java-5.1.13-Bin.jar를 다운로드하십시오. http://maven.outofmemory.cn/org.mybatis.generator/mybatis-generator-core/1.3.2/ 다운로드 할 수 있습니다.
2. 새 폴더를 만들고 MyBatis-Generator-Core-1.3.2.jar 및 MySQL-Connector-Java-5.1.13-Bin.jar를 폴더로 다운로드 한 후 폴더의 루트 디렉토리에 새 SRC 폴더를 만듭니다.
3. 폴더의 루트 디렉토리에 새 txt 텍스트 문서를 작성하고 코드를 작성하십시오.
Java -jar mybatis -generator -core -1.3.2.jar -configfile generatorconfig.xml -werwrite
그런 다음 txt 텍스트 문서의 파일 이름 접미사를 BAT로 변경하십시오.
4. 새 GeneratorConfig.xml을 생성하고 다음과 같이 리버스 엔지니어링 정보를 구성하십시오.
<? xml 버전 = "1.0"encoding = "utf-8"?> <! doctype generatorconfigurationpublic "-// mybatis.org//dtd mybatis 생성기 구성 1.0 // en ""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd "> <GeneratorConfiguration> <classPathentry 위치 ="MySQL-connector-java-5.1.13-bin.jar "/> <Context ID ="DB2Tables " TargetRuntime = "MyBatis3"> <CommentGenerator> <속성 이름 = "suppressDate"value = "true"/> <속성 이름 = "suppressAllComments"value = "true"/> </commentgenerator> <!-데이터베이스 연결 구성-> <jdbcconnection driver class = "com.mysql.jdbc.driver" ConnectionUrl = "jdbc : mysql : // localhost : 3306/login"userId = "root"password = "root"> </jdbcConnection> <javatyperesolver> <propertbigdecimals "value ="false "/> </javatyperesolver> <!-Configure the Configure intity intity entity entity intity intity intity th the configure. TargetPackage = "tse.model"targetProject = "src"> <property name = "enablesubpackages"value = "true"/<속성 이름 = "trimstrings"value = "true"/> </javamodelgenerator> <!-생성 된 xml-> <sqlmapgenerator targetpackage = "targeproject =" "sqlmapgenerator targetpackage ="targepo. 이름 = "enablebpackages"value = "true"/> </sqlmapgenerator> <!-생성 된 매핑 인터페이스를 구성-> <javaclientgenerator type = "xmlmapper"targetpackage = "tse.mapping"targetProject = "src"> 리버스 엔지니어링 테이블 구성, TableName은 WildCard %-> <Table TableName = "Login"DomainObjectName = "Login"enableCountByExample = "false"enableUpDateByexample = "false"enabledeTeTeByexample = "false"enablectbyexample = "false" SelectByexampseQuleyId = "false"> </table> </context> </generatorconfiguration>
JDBCConnection 태그의 데이터베이스 연결 구성 및 테이블 태그의 TableName 속성 구성을 수정하십시오. 데이터베이스의 모든 테이블이 엔지니어링을 반전하려는 경우 모든 테이블과 일치하도록 Tablemename 값을 %로 직접 설정할 수 있습니다. 그러나 현재 DomainObjectName 속성을 제거해야합니다.
자, 위의 단계를 통해 전체 디렉토리 구조는 다음과 같아야합니다.
SRC 폴더는 여전히 빈 폴더입니다
현재 루트 디렉토리에서 BAT 파일을 실행하면 원하는 코드가 SRC 디렉토리에서 생성되었음을 알 수 있습니다.
위의 것은 편집자가 귀하에게 소개 한 Mybatis 역 엔지니어링 사용에 대한 관련 지식입니다. 주로 역 엔지니어링의 사용을 소개합니다. 현재 친구가 물어볼 것입니다. 역 엔지니어링이 어떻게 직접 정의한 코드 형식을 생성 할 수 있습니까? 걱정하지 마십시오. 다음 기사에서 Mybatis-Generator-Core-1.3.2.jar 패키지의 수정 및 포장에 대해 이야기하겠습니다. 관심있는 친구들은이 사이트를 계속 따르고 있습니다!