Idea中Mybatis工具插件结合mysql自动生成实体类和mapper层的增删改查

Idea中Mybatis工具插件结合mysql自动生成实体类和mapper层的增删改查

1:Free Mybatis Tool插件的下载

File->Setting

Idea中Mybatis工具插件结合mysql自动生成实体类和mapper层的增删改查_第1张图片

2:配置数据源

Idea中Mybatis工具插件结合mysql自动生成实体类和mapper层的增删改查_第2张图片
Idea中Mybatis工具插件结合mysql自动生成实体类和mapper层的增删改查_第3张图片

3:点击table使用Mybatis-Generator生成

Idea中Mybatis工具插件结合mysql自动生成实体类和mapper层的增删改查_第4张图片
工具使用
Idea中Mybatis工具插件结合mysql自动生成实体类和mapper层的增删改查_第5张图片

4:结果

Idea中Mybatis工具插件结合mysql自动生成实体类和mapper层的增删改查_第6张图片
Demo实体接口

@Data
public class Demo implements Serializable {
    private Integer id;
    private String username;
    private static final long serialVersionUID = 1L;
}

DemoDao接口

public interface DemoDao {
    int deleteByPrimaryKey(Integer id);

    int insert(Demo record);

    int insertSelective(Demo record);

    Demo selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Demo record);

    int updateByPrimaryKey(Demo record);
}

DemoMapper.xml


DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yjr.rj1902_g4_demo.dao.DemoDao">
  <resultMap id="BaseResultMap" type="com.yjr.rj1902_g4_demo.bean.Demo">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="username" jdbcType="VARCHAR" property="username" />
  resultMap>
  <sql id="Base_Column_List">
    id, username
  sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from demo
    where id = #{id,jdbcType=INTEGER}
  select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from demo
    where id = #{id,jdbcType=INTEGER}
  delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yjr.rj1902_g4_demo.bean.Demo" useGeneratedKeys="true">
    insert into demo (username)
    values (#{username,jdbcType=VARCHAR})
  insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yjr.rj1902_g4_demo.bean.Demo" useGeneratedKeys="true">
    insert into demo
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="username != null">
        username,
      if>
    trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="username != null">
        #{username,jdbcType=VARCHAR},
      if>
    trim>
  insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.yjr.rj1902_g4_demo.bean.Demo">
    update demo
    <set>
      <if test="username != null">
        username = #{username,jdbcType=VARCHAR},
      if>
    set>
    where id = #{id,jdbcType=INTEGER}
  update>
  <update id="updateByPrimaryKey" parameterType="com.yjr.rj1902_g4_demo.bean.Demo">
    update demo
    set username = #{username,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  update>
mapper>

你可能感兴趣的:(mybatis,intellij-idea,mysql)