Spring+SpringMVC+Mybatis(开发必备技能)04、mybatis自动生成mapper_dao_model(包
【摘要】 编辑Spring+SpringMVC+Mybatis(开发必备技能)04、mybatis自动生成mapper_dao_model(包含工具与视频讲解) 纯绿色版本、配套使用视频,100%运行成功下载链接:mybatis自动生成mapper_dao_model(包含工具与视频讲解)纯绿色版本、配套使用视频,100%运行成功。-Java文档类资源-CSDN下载视频教程链接:common_u...
Spring+SpringMVC+Mybatis(开发必备技能)
04、mybatis自动生成mapper_dao_model(包含工具与视频讲解) 纯绿色版本、配套使用视频,100%运行成功
下载链接:mybatis自动生成mapper_dao_model(包含工具与视频讲解)纯绿色版本、配套使用视频,100%运行成功。-Java文档类资源-CSDN下载
视频教程链接:
common_utils配套使用视频_哔哩哔哩_bilibili
目录
1、配置文件:
其中修改数据库账号密码和链接就行
<?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="mysql-connector-java-5.1.24-bin.jar"/>
<context id="DB2Tables" targetRuntime="MyBatis3">
<!-- 生成的代码注释,加入下面的配置控制 false:生成、true:不生成 -->
<commentGenerator>
<property name="suppressAllComments" value="false"/>
<property name="suppressDate" value="false"/>
</commentGenerator>
<!-- 数据库连接URL、用户名、密码 -->
<!-- Oracle连接
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:@localhost:1521:orcl"
userId="tiger" password="123456">
</jdbcConnection>
-->
<!-- MySQL连接 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/test?characterEncoding=utf8"
userId="root" password="root">
</jdbcConnection>
<!-- java类型处理器 -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- Model位置 -->
<javaModelGenerator targetPackage="main.java.com.item.model" targetProject="D:\laoshifu_hongmuxiangxun\">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- mapper位置 -->
<sqlMapGenerator targetPackage="main.resources.mapper" targetProject="D:\laoshifu_hongmuxiangxun\">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- dao位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="main.java.com.item.dao" targetProject="D:\laoshifu_hongmuxiangxun\">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- %代表生成所有的表,如果只想生成某表,自己改成表名字就行 -->
<table tableName="%" schema="SCOTT" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" ></table>
</context>
</generatorConfiguration>
2、脚本文件:
chcp 65001
echo off
title AutoMybatis_laoshifu
mkdir D:\laoshifu_hongmuxiangxun
cls
java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite
start D:\laoshifu_hongmuxiangxun
echo 如果生成正确,代码会生成在D盘的根目录下,结构为,java/com与java/resources可以直接复制,看到successfully代表生成完毕,按任意键结束。
pause
执行文件:
3、执行效果:
生成并打开对应生成文件夹位置:
生成mapper.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="main.java.com.item.dao.UsersMapper" >
<resultMap id="BaseResultMap" type="main.java.com.item.model.Users" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sat May 28 16:28:01 CST 2022.
-->
<id column="id" property="id" jdbcType="INTEGER" />
<result column="createDate" property="createdate" jdbcType="TIMESTAMP" />
<result column="userName" property="username" jdbcType="VARCHAR" />
<result column="introduce" property="introduce" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sat May 28 16:28:01 CST 2022.
-->
id, createDate, userName, introduce
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sat May 28 16:28:01 CST 2022.
-->
select
<include refid="Base_Column_List" />
from users
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sat May 28 16:28:01 CST 2022.
-->
delete from users
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="main.java.com.item.model.Users" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sat May 28 16:28:01 CST 2022.
-->
insert into users (id, createDate, userName,
introduce)
values (#{id,jdbcType=INTEGER}, #{createdate,jdbcType=TIMESTAMP}, #{username,jdbcType=VARCHAR},
#{introduce,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="main.java.com.item.model.Users" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sat May 28 16:28:01 CST 2022.
-->
insert into users
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="createdate != null" >
createDate,
</if>
<if test="username != null" >
userName,
</if>
<if test="introduce != null" >
introduce,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="createdate != null" >
#{createdate,jdbcType=TIMESTAMP},
</if>
<if test="username != null" >
#{username,jdbcType=VARCHAR},
</if>
<if test="introduce != null" >
#{introduce,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="main.java.com.item.model.Users" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sat May 28 16:28:01 CST 2022.
-->
update users
<set >
<if test="createdate != null" >
createDate = #{createdate,jdbcType=TIMESTAMP},
</if>
<if test="username != null" >
userName = #{username,jdbcType=VARCHAR},
</if>
<if test="introduce != null" >
introduce = #{introduce,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="main.java.com.item.model.Users" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sat May 28 16:28:01 CST 2022.
-->
update users
set createDate = #{createdate,jdbcType=TIMESTAMP},
userName = #{username,jdbcType=VARCHAR},
introduce = #{introduce,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
生成model文件示例:
package main.java.com.item.model;
import java.util.Date;
public class Users {
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column users.id
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
private Integer id;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column users.createDate
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
private Date createdate;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column users.userName
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
private String username;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column users.introduce
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
private String introduce;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column users.id
*
* @return the value of users.id
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
public Integer getId() {
return id;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column users.id
*
* @param id the value for users.id
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
public void setId(Integer id) {
this.id = id;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column users.createDate
*
* @return the value of users.createDate
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
public Date getCreatedate() {
return createdate;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column users.createDate
*
* @param createdate the value for users.createDate
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
public void setCreatedate(Date createdate) {
this.createdate = createdate;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column users.userName
*
* @return the value of users.userName
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
public String getUsername() {
return username;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column users.userName
*
* @param username the value for users.userName
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
public void setUsername(String username) {
this.username = username == null ? null : username.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column users.introduce
*
* @return the value of users.introduce
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
public String getIntroduce() {
return introduce;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column users.introduce
*
* @param introduce the value for users.introduce
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
public void setIntroduce(String introduce) {
this.introduce = introduce == null ? null : introduce.trim();
}
}
生成dao层文件示例:
package main.java.com.item.dao;
import main.java.com.item.model.Users;
public interface UsersMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table users
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table users
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
int insert(Users record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table users
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
int insertSelective(Users record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table users
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
Users selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table users
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
int updateByPrimaryKeySelective(Users record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table users
*
* @mbggenerated Sat May 28 16:28:01 CST 2022
*/
int updateByPrimaryKey(Users record);
}
推荐
华为开发者空间发布
让每位开发者拥有一台云主机
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)