eclipse中利用Maven逆向工程生成PO类以及mapper(mybatis)
在pom.xml的project>build里面添加如下代码,让maven环境支持mybatis-generator组件
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.mybatis.generator</groupId>
- <artifactId>mybatis-generator-maven-plugin</artifactId>
- <version>1.3.2</version>
- <configuration>
- <configurationFile>src/main/resources/generator.xml</configurationFile>
- <verbose>true</verbose>
- <overwrite>true</overwrite>
- </configuration>
- <executions>
- <execution>
- <id>Generate MyBatis Artifacts</id>
- <goals>
- <goal>generate</goal>
- </goals>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>org.mybatis.generator</groupId>
- <artifactId>mybatis-generator-core</artifactId>
- <version>1.3.2</version>
- </dependency>
- </dependencies>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.19.1</version>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <version>3.0.1</version>
- <configuration>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
注:如果在dependencies中已经引入mysql-connector-java则不需加入以下dependency,反之加入
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.35</version>
- <scope>runtime</scope>
- </dependency>
2、generator.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>
- <!-- 数据库驱动包位置 -->
- <classPathEntry
- location="E:\apache-maven-3.3.9\repo\mysql\mysql-connector-java\5.1.18\mysql-connector-java-5.1.18.jar" />
- <context id="Tables" targetRuntime="MyBatis3">
- <commentGenerator>
- <!-- 是否去除自动生成的注释 true:是 : false:否 -->
- <property name="suppressAllComments" value="true" />
- </commentGenerator>
- <!-- 数据库链接URL、用户名、密码 -->
- <jdbcConnection driverClass="com.mysql.jdbc.Driver"
- connectionURL="jdbc:mysql://192.168.100.52:3306/dev_test" userId="数据库用户名"
- password="数据库密码">
- <!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl"
- userId="msa" password="msa"> -->
- </jdbcConnection>
- <javaTypeResolver>
- <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer, 为 true时把JDBC DECIMAL和NUMERIC类型解析为java.math.BigDecimal -->
- <property name="forceBigDecimals" value="true" />
- </javaTypeResolver>
- <!-- 生成实体类的包名和位置,这里配置将生成的实体类放在com.loan.test.entity这个包下 -->
- <javaModelGenerator targetPackage="com.loan.test.entity"
- targetProject=".\src\main\java\">
- <!-- enableSubPackages:是否让schema作为包的后缀 -->
- <property name="enableSubPackages" value="true" />
- <!-- 从数据库返回的值被清理前后的空格 -->
- <property name="trimStrings" value="true" />
- </javaModelGenerator>
- <!-- 生成的SQL映射文件包名和位置,这里配置将生成的SQL映射文件放在com.loan.test.dao.xml这个包下 -->
- <sqlMapGenerator targetPackage="com.loan.test.dao.xml"
- targetProject=".\src\main\java\">
- <!-- enableSubPackages:是否让schema作为包的后缀 -->
- <property name="enableSubPackages" value="true" />
- </sqlMapGenerator>
- <!-- 生成DAO的包名和位置,这里配置将生成的dao类放在com.loan.test.dao.mapper这个包下 -->
- <javaClientGenerator type="XMLMAPPER"
- targetPackage="com.loan.test.dao.mapper" targetProject=".\src\main\java\">
- <!-- enableSubPackages:是否让schema作为包的后缀 -->
- <property name="enableSubPackages" value="true" />
- </javaClientGenerator>
- <!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
- <table tableName="test" domainObjectName="Test"
- enableCountByExample="false" enableUpdateByExample="false"
- enableDeleteByExample="false" enableSelectByExample="false"
- selectByExampleQueryId="false" />
- </context>
- </generatorConfiguration>
3、运用maven指令生成逆向工程
项目右键->run as->maven build...,Goals:中输入mybatis-generator:generate
.
4、刷新项目,结果
1)Test.java
- package com.loan.test.entity;
- import java.math.BigDecimal;
- public class Test {
- private Integer id;
- private String userName;
- private Integer cardId;
- private BigDecimal moneyAmount;
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- public String getUserName() {
- return userName;
- }
- public void setUserName(String userName) {
- this.userName = userName == null ? null : userName.trim();
- }
- public Integer getCardId() {
- return cardId;
- }
- public void setCardId(Integer cardId) {
- this.cardId = cardId;
- }
- public BigDecimal getMoneyAmount() {
- return moneyAmount;
- }
- public void setMoneyAmount(BigDecimal moneyAmount) {
- this.moneyAmount = moneyAmount;
- }
- }
2)TestMapper.java
- package com.loan.test.dao.mapper;
- import com.loan.test.entity.Test;
- public interface TestMapper {
- int deleteByPrimaryKey(Integer id);
- int insert(Test record);
- int insertSelective(Test record);
- Test selectByPrimaryKey(Integer id);
- int updateByPrimaryKeySelective(Test record);
- int updateByPrimaryKey(Test record);
- }
3)TestMapper.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.loan.test.dao.mapper.TestMapper">
- <resultMap id="BaseResultMap" type="com.loan.test.entity.Test">
- <id column="id" jdbcType="INTEGER" property="id" />
- <result column="user_name" jdbcType="VARCHAR" property="userName" />
- <result column="card_id" jdbcType="INTEGER" property="cardId" />
- <result column="money_amount" jdbcType="DECIMAL" property="moneyAmount" />
- </resultMap>
- <sql id="Base_Column_List">
- id, user_name, card_id, money_amount
- </sql>
- <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
- select
- <include refid="Base_Column_List" />
- from test
- where id = #{id,jdbcType=INTEGER}
- </select>
- <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
- delete from test
- where id = #{id,jdbcType=INTEGER}
- </delete>
- <insert id="insert" parameterType="com.loan.test.entity.Test">
- insert into test (id, user_name, card_id,
- money_amount)
- values (#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{cardId,jdbcType=INTEGER},
- #{moneyAmount,jdbcType=DECIMAL})
- </insert>
- <insert id="insertSelective" parameterType="com.loan.test.entity.Test">
- insert into test
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="id != null">
- id,
- </if>
- <if test="userName != null">
- user_name,
- </if>
- <if test="cardId != null">
- card_id,
- </if>
- <if test="moneyAmount != null">
- money_amount,
- </if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="id != null">
- #{id,jdbcType=INTEGER},
- </if>
- <if test="userName != null">
- #{userName,jdbcType=VARCHAR},
- </if>
- <if test="cardId != null">
- #{cardId,jdbcType=INTEGER},
- </if>
- <if test="moneyAmount != null">
- #{moneyAmount,jdbcType=DECIMAL},
- </if>
- </trim>
- </insert>
- <update id="updateByPrimaryKeySelective" parameterType="com.loan.test.entity.Test">
- update test
- <set>
- <if test="userName != null">
- user_name = #{userName,jdbcType=VARCHAR},
- </if>
- <if test="cardId != null">
- card_id = #{cardId,jdbcType=INTEGER},
- </if>
- <if test="moneyAmount != null">
- money_amount = #{moneyAmount,jdbcType=DECIMAL},
- </if>
- </set>
- where id = #{id,jdbcType=INTEGER}
- </update>
- <update id="updateByPrimaryKey" parameterType="com.loan.test.entity.Test">
- update test
- set user_name = #{userName,jdbcType=VARCHAR},
- card_id = #{cardId,jdbcType=INTEGER},
- money_amount = #{moneyAmount,jdbcType=DECIMAL}
- where id = #{id,jdbcType=INTEGER}
- </update>
- <resultMap id="BaseResultMap" type="com.loan.test.entity.Test">
- <id column="id" jdbcType="INTEGER" property="id" />
- <result column="user_name" jdbcType="VARCHAR" property="userName" />
- <result column="card_id" jdbcType="INTEGER" property="cardId" />
- <result column="money_amount" jdbcType="DECIMAL" property="moneyAmount" />
- </resultMap>
- <sql id="Base_Column_List">
- id, user_name, card_id, money_amount
- </sql>
- <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
- select
- <include refid="Base_Column_List" />
- from test
- where id = #{id,jdbcType=INTEGER}
- </select>
- <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
- delete from test
- where id = #{id,jdbcType=INTEGER}
- </delete>
- <insert id="insert" parameterType="com.loan.test.entity.Test">
- insert into test (id, user_name, card_id,
- money_amount)
- values (#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{cardId,jdbcType=INTEGER},
- #{moneyAmount,jdbcType=DECIMAL})
- </insert>
- <insert id="insertSelective" parameterType="com.loan.test.entity.Test">
- insert into test
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="id != null">
- id,
- </if>
- <if test="userName != null">
- user_name,
- </if>
- <if test="cardId != null">
- card_id,
- </if>
- <if test="moneyAmount != null">
- money_amount,
- </if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="id != null">
- #{id,jdbcType=INTEGER},
- </if>
- <if test="userName != null">
- #{userName,jdbcType=VARCHAR},
- </if>
- <if test="cardId != null">
- #{cardId,jdbcType=INTEGER},
- </if>
- <if test="moneyAmount != null">
- #{moneyAmount,jdbcType=DECIMAL},
- </if>
- </trim>
- </insert>
- <update id="updateByPrimaryKeySelective" parameterType="com.loan.test.entity.Test">
- update test
- <set>
- <if test="userName != null">
- user_name = #{userName,jdbcType=VARCHAR},
- </if>
- <if test="cardId != null">
- card_id = #{cardId,jdbcType=INTEGER},
- </if>
- <if test="moneyAmount != null">
- money_amount = #{moneyAmount,jdbcType=DECIMAL},
- </if>
- </set>
- where id = #{id,jdbcType=INTEGER}
- </update>
- <update id="updateByPrimaryKey" parameterType="com.loan.test.entity.Test">
- update test
- set user_name = #{userName,jdbcType=VARCHAR},
- card_id = #{cardId,jdbcType=INTEGER},
- money_amount = #{moneyAmount,jdbcType=DECIMAL}
- where id = #{id,jdbcType=INTEGER}
- </update>
- </mapper>
配置完成!!
eclipse中利用Maven逆向工程生成PO类以及mapper(mybatis)的更多相关文章
- 在Eclipse中利用maven整合搭建ssm框架
首先说明用到的框架: spring + springMVC + mybatis 构建工具:maven 开发工具:eclipse 开发环境:win10 java版本:jdk1.8 ...
- 利用Eclipse中的Maven构建Web项目(三)
利用Eclipse中的Maven构建Web项目 1.将Maven Project转换成动态Web项目,鼠标右键项目,输入"Project Facets" 2.依据Dynamic W ...
- 利用Eclipse中的Maven构建Web项目报错(二)
利用Eclipse中的Maven构建Web项目 1.错误描述 [INFO] Scanning for projects... [INFO] [INFO] Using the builder org.a ...
- 利用Eclipse中的Maven构建Web项目报错(一)
利用Eclipse中的Maven构建Web项目 1.在进行上述操作时,pom.xml一直报错 <project xmlns="http://maven.apache.org/POM/4 ...
- 利用Eclipse中的Maven构建Web项目(二)
利用Eclipse中的Maven构建Web项目 1.新建源文件夹,Java Resources鼠标右键,"New-->Source Folder" 2.新建src/main/ ...
- 利用Eclipse中的Maven构建Web项目(一)
利用Eclipse中的Maven构建Web项目 1.新建一个Maven Project,"New-->Other..." 2.选择"Maven Project&qu ...
- Eclipse中发布Maven管理的Web项目时找不到类的问题根源和解决办法(转)
转自:http://blog.csdn.net/lvguanming/article/details/37812579?locationNum=12 写在前面的话 现在是越来越太原讨厌Eclipse这 ...
- Maven学习(一) -- 安装Maven及Eclipse中配置Maven
标签(空格分隔): 学习笔记 本文环境:Windows7, JDK1.7.0_76 安装及配置Maven环境变量 需要电脑中已经有Java环境 在控制台中输入:echo %JAVA_HOME%看是否能 ...
- Eclipse 中构建 Maven 项目的完整过程 - SpringBoot 项目
进行以下步骤的前提是你已经安装好本地maven库和eclipse中的maven插件了(有的eclipse中已经集成了maven插件) 一.Maven项目的新建 1.鼠标右键---->New--- ...
- Mybatis逆向工程生成po、mapper接口、mapper.xml
Mybatis逆向工程生成po.mapper接口.mapper.xml 一.新建一个maven工程 请查看我的另一篇博客:<使用idea创建一个maven工程> 二.引入所需依赖 需要my ...
随机推荐
- 原生js创建节点,添加节点,删除节点
1.操作 var tab=document.querySelector('#app .bpm-container'); var abcbox=document.querySelector('.abcb ...
- Metasploit渗透测试框架一
Metasploit简介 Metasploit是一个渗透测试平台,使您能够查找,利用和验证漏洞.该平台还有Metasploit Pro. Metasploit是一个免费的.可下载的框架,本身自带数百已 ...
- 为开源项目贡献代码-pycharm使用git-登录注册功能分析-判断手机号存在接口-多种方式登录接口-腾讯云短信申请
目录 为开源项目贡献代码-pycharm使用git-登录注册功能分析-判断手机号存在接口-多种方式登录接口-腾讯云短信申请 git内容大回顾 今日内容概要 今日内容详细 1 为开源项目贡献代码 2 p ...
- ctfshow web入门 命令执行 37-39
37-39 基于 GET 传参的 include() 38.39 是 37 的变种 分析 伪协议常用于文件包含漏洞中 文件包含函数有:include.include_once.require.requ ...
- python 操作 ES 二、mappings
环境 python:3.8 es:7.8.0 环境安装 pip install elasticsearch==7.8.0 from elasticsearch import Elasticsearch ...
- 直播软件搭建,姓名,身份证input验证过滤
直播软件搭建,姓名,身份证input验证过滤 姓名验证:需求,可输入英文.汉字 for(let i=0;i<e.length;i++){ if(/^[a-zA-Z\u4e00-\u9fa5]+ ...
- syntax_lead_x.txt
select lead( t1.field_date-1, 1, null ) over(partition by t1.field_str order by t1.field_str),*from ...
- Educational Codeforces Round 112 (Rated for Div
Educational Codeforces Round 112 (Rated for Div. 2) CodeForces - 1555D Say No to Palindromes 如果一个字符串 ...
- dom-utils
function isNil(obj:any): boolean { return typeof obj === "undefined" || obj === null;}func ...
- 检测到远端rexec服务正在运行中
0.系统 AIX7 1.先备份 /etc/inetd.conf文件 2.vi /etc/inetd.conf vi /etc/inetd.conf ##给原来的行加上注释# # exec .... / ...