Skip to content

Commit c81ebfd

Browse files
committedMay 5, 2019
利用 mybatis-generator 插件自动生成代码
* generatorConfig.xml 中的 jdbcConnection 添加子配置 nullCatalogMeansCurrent, 防止生成系统的表或字段 * user 表取消 schema,因为 mysql 不支持 * idea maven 窗口中,Plugins 子项->mybatis-generator展开,双击generate即可自动生成
1 parent 6546c03 commit c81ebfd

File tree

8 files changed

+325
-11
lines changed

8 files changed

+325
-11
lines changed
 

‎.idea/workspace.xml

+48-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.wishuok.mapper;
2+
3+
import com.wishuok.pojo.Role;
4+
5+
public interface RoleMapper {
6+
int deleteByPrimaryKey(String id);
7+
8+
int insert(Role record);
9+
10+
int insertSelective(Role record);
11+
12+
Role selectByPrimaryKey(String id);
13+
14+
int updateByPrimaryKeySelective(Role record);
15+
16+
int updateByPrimaryKey(Role record);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.wishuok.mapper;
2+
3+
import com.wishuok.pojo.User;
4+
5+
public interface UserMapper {
6+
int deleteByPrimaryKey(String id);
7+
8+
int insert(User record);
9+
10+
int insertSelective(User record);
11+
12+
User selectByPrimaryKey(String id);
13+
14+
int updateByPrimaryKeySelective(User record);
15+
16+
int updateByPrimaryKey(User record);
17+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.wishuok.pojo;
2+
3+
import java.io.Serializable;
4+
5+
public class Role implements Serializable {
6+
private String id;
7+
8+
private String roleName;
9+
10+
private String note;
11+
12+
private static final long serialVersionUID = 1L;
13+
14+
public String getId() {
15+
return id;
16+
}
17+
18+
public void setId(String id) {
19+
this.id = id == null ? null : id.trim();
20+
}
21+
22+
public String getRoleName() {
23+
return roleName;
24+
}
25+
26+
public void setRoleName(String roleName) {
27+
this.roleName = roleName == null ? null : roleName.trim();
28+
}
29+
30+
public String getNote() {
31+
return note;
32+
}
33+
34+
public void setNote(String note) {
35+
this.note = note == null ? null : note.trim();
36+
}
37+
}
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.wishuok.pojo;
2+
3+
import java.io.Serializable;
4+
5+
public class User implements Serializable {
6+
private String id;
7+
8+
private String username;
9+
10+
private Integer sex;
11+
12+
private Integer accounttype;
13+
14+
private static final long serialVersionUID = 1L;
15+
16+
public String getId() {
17+
return id;
18+
}
19+
20+
public void setId(String id) {
21+
this.id = id == null ? null : id.trim();
22+
}
23+
24+
public String getUsername() {
25+
return username;
26+
}
27+
28+
public void setUsername(String username) {
29+
this.username = username == null ? null : username.trim();
30+
}
31+
32+
public Integer getSex() {
33+
return sex;
34+
}
35+
36+
public void setSex(Integer sex) {
37+
this.sex = sex;
38+
}
39+
40+
public Integer getAccounttype() {
41+
return accounttype;
42+
}
43+
44+
public void setAccounttype(Integer accounttype) {
45+
this.accounttype = accounttype;
46+
}
47+
}

‎src/main/resources/generatorConfig.xml

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
<jdbcConnection driverClass="${jdbc.driver}"
2323
connectionURL="${jdbc.url}"
2424
userId="${jdbc.username}"
25-
password="${jdbc.password}" />
25+
password="${jdbc.password}" >
26+
<!--MySQL 不支持 schema 或者 catalog 所以需要添加这个-->
27+
<!--参考 : http://www.mybatis.org/generator/usage/mysql.html-->
28+
<property name="nullCatalogMeansCurrent" value="true"/>
29+
</jdbcConnection>
2630

2731
<!-- 类型转换 -->
2832
<javaTypeResolver>
@@ -49,7 +53,7 @@
4953
</javaClientGenerator>
5054

5155
<!--要生成的数据库表-->
52-
<table schema="test" tableName="user" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
56+
<table tableName="user" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
5357
<!--字段名称使用骆驼命名方式:dept_no 变为deptNo-->
5458
<property name="useActualColumnNames" value="false" />
5559
</table>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3+
<mapper namespace="com.wishuok.mapper.RoleMapper">
4+
<resultMap id="BaseResultMap" type="com.wishuok.pojo.Role">
5+
<id column="id" jdbcType="VARCHAR" property="id" />
6+
<result column="RoleName" jdbcType="VARCHAR" property="roleName" />
7+
<result column="Note" jdbcType="VARCHAR" property="note" />
8+
</resultMap>
9+
<sql id="Base_Column_List">
10+
id, RoleName, Note
11+
</sql>
12+
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
13+
select
14+
<include refid="Base_Column_List" />
15+
from role
16+
where id = #{id,jdbcType=VARCHAR}
17+
</select>
18+
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
19+
delete from role
20+
where id = #{id,jdbcType=VARCHAR}
21+
</delete>
22+
<insert id="insert" parameterType="com.wishuok.pojo.Role">
23+
insert into role (id, RoleName, Note
24+
)
25+
values (#{id,jdbcType=VARCHAR}, #{roleName,jdbcType=VARCHAR}, #{note,jdbcType=VARCHAR}
26+
)
27+
</insert>
28+
<insert id="insertSelective" parameterType="com.wishuok.pojo.Role">
29+
insert into role
30+
<trim prefix="(" suffix=")" suffixOverrides=",">
31+
<if test="id != null">
32+
id,
33+
</if>
34+
<if test="roleName != null">
35+
RoleName,
36+
</if>
37+
<if test="note != null">
38+
Note,
39+
</if>
40+
</trim>
41+
<trim prefix="values (" suffix=")" suffixOverrides=",">
42+
<if test="id != null">
43+
#{id,jdbcType=VARCHAR},
44+
</if>
45+
<if test="roleName != null">
46+
#{roleName,jdbcType=VARCHAR},
47+
</if>
48+
<if test="note != null">
49+
#{note,jdbcType=VARCHAR},
50+
</if>
51+
</trim>
52+
</insert>
53+
<update id="updateByPrimaryKeySelective" parameterType="com.wishuok.pojo.Role">
54+
update role
55+
<set>
56+
<if test="roleName != null">
57+
RoleName = #{roleName,jdbcType=VARCHAR},
58+
</if>
59+
<if test="note != null">
60+
Note = #{note,jdbcType=VARCHAR},
61+
</if>
62+
</set>
63+
where id = #{id,jdbcType=VARCHAR}
64+
</update>
65+
<update id="updateByPrimaryKey" parameterType="com.wishuok.pojo.Role">
66+
update role
67+
set RoleName = #{roleName,jdbcType=VARCHAR},
68+
Note = #{note,jdbcType=VARCHAR}
69+
where id = #{id,jdbcType=VARCHAR}
70+
</update>
71+
</mapper>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3+
<mapper namespace="com.wishuok.mapper.UserMapper">
4+
<resultMap id="BaseResultMap" type="com.wishuok.pojo.User">
5+
<id column="id" jdbcType="VARCHAR" property="id" />
6+
<result column="UserName" jdbcType="VARCHAR" property="username" />
7+
<result column="Sex" jdbcType="INTEGER" property="sex" />
8+
<result column="AccountType" jdbcType="INTEGER" property="accounttype" />
9+
</resultMap>
10+
<sql id="Base_Column_List">
11+
id, UserName, Sex, AccountType
12+
</sql>
13+
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
14+
select
15+
<include refid="Base_Column_List" />
16+
from user
17+
where id = #{id,jdbcType=VARCHAR}
18+
</select>
19+
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
20+
delete from user
21+
where id = #{id,jdbcType=VARCHAR}
22+
</delete>
23+
<insert id="insert" parameterType="com.wishuok.pojo.User">
24+
insert into user (id, UserName, Sex,
25+
AccountType)
26+
values (#{id,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{sex,jdbcType=INTEGER},
27+
#{accounttype,jdbcType=INTEGER})
28+
</insert>
29+
<insert id="insertSelective" parameterType="com.wishuok.pojo.User">
30+
insert into user
31+
<trim prefix="(" suffix=")" suffixOverrides=",">
32+
<if test="id != null">
33+
id,
34+
</if>
35+
<if test="username != null">
36+
UserName,
37+
</if>
38+
<if test="sex != null">
39+
Sex,
40+
</if>
41+
<if test="accounttype != null">
42+
AccountType,
43+
</if>
44+
</trim>
45+
<trim prefix="values (" suffix=")" suffixOverrides=",">
46+
<if test="id != null">
47+
#{id,jdbcType=VARCHAR},
48+
</if>
49+
<if test="username != null">
50+
#{username,jdbcType=VARCHAR},
51+
</if>
52+
<if test="sex != null">
53+
#{sex,jdbcType=INTEGER},
54+
</if>
55+
<if test="accounttype != null">
56+
#{accounttype,jdbcType=INTEGER},
57+
</if>
58+
</trim>
59+
</insert>
60+
<update id="updateByPrimaryKeySelective" parameterType="com.wishuok.pojo.User">
61+
update user
62+
<set>
63+
<if test="username != null">
64+
UserName = #{username,jdbcType=VARCHAR},
65+
</if>
66+
<if test="sex != null">
67+
Sex = #{sex,jdbcType=INTEGER},
68+
</if>
69+
<if test="accounttype != null">
70+
AccountType = #{accounttype,jdbcType=INTEGER},
71+
</if>
72+
</set>
73+
where id = #{id,jdbcType=VARCHAR}
74+
</update>
75+
<update id="updateByPrimaryKey" parameterType="com.wishuok.pojo.User">
76+
update user
77+
set UserName = #{username,jdbcType=VARCHAR},
78+
Sex = #{sex,jdbcType=INTEGER},
79+
AccountType = #{accounttype,jdbcType=INTEGER}
80+
where id = #{id,jdbcType=VARCHAR}
81+
</update>
82+
</mapper>

0 commit comments

Comments
 (0)
Please sign in to comment.