//对于数据库单表增删改查,为缩短开发效率,借助idea和mybatis的插件构建一套持久层业务
//idea 连接数据库
DataBase --> mysql -->连接数据库
//集成mybatis插件
pom.xml配置
<!-- mybatis generator 自动生成代码插件 --> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.7</version> <configuration> <configurationFile>src/main/resources/generator/generatorConfig.xml</configurationFile> <overwrite>true</overwrite> <verbose>true</verbose> </configuration> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.37</version> </dependency> </dependencies> </plugin>
//添加mybatis的generator.xml
// resources --> generator --> generatorConfig.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <generatorConfiguration> <context id="Mysql" targetRuntime="MyBatis3" defaultModelType="flat"> <property name="autoDelimitKeywords" value="true"/> <property name="beginningDelimiter" value="`"/> <property name="endingDelimiter" value="`"/> <!--覆盖生成XML文件--> <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" /> <!-- 生成的实体类添加toString()方法 --> <plugin type="org.mybatis.generator.plugins.ToStringPlugin" /> <!-- 不生成注释 --> <commentGenerator> <property name="suppressAllComments" value="true"/> </commentGenerator> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="" userId="" password=""> </jdbcConnection> <!-- domain/pojo 类的位置 --> <javaModelGenerator targetProject="srcmainjava" targetPackage="com.swust.server.pojo"/> <!-- mapper xml的位置 --> <sqlMapGenerator targetProject="srcmain esources" targetPackage="mybatismapper"/> <!-- mapper类的位置 --> <javaClientGenerator targetProject="srcmainjava" targetPackage="com.swust.server.mapper" type="XMLMAPPER" /> <table tableName="tb_area" domainObjectName="Area"/> </context> </generatorConfiguration>
// 构建maven启动指令
Edit --> maven -->
// command
mybatis-generator:generate -e