Skip to content

Commit 835cafa

Browse files
committed
修复生成代码的bug
1 parent c041d85 commit 835cafa

File tree

7 files changed

+543
-572
lines changed

7 files changed

+543
-572
lines changed

.idea/workspace.xml

Lines changed: 415 additions & 565 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

springboot-mybatis-demo.iml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<orderEntry type="module-library">
9090
<library name="Maven: com.alibaba:jconsole:1.8.0">
9191
<CLASSES>
92-
<root url="jar://D:/Program Files/jdk8/lib/jconsole.jar!/" />
92+
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/lib/jconsole.jar!/" />
9393
</CLASSES>
9494
<JAVADOC />
9595
<SOURCES />
@@ -98,7 +98,7 @@
9898
<orderEntry type="module-library">
9999
<library name="Maven: com.alibaba:tools:1.8.0">
100100
<CLASSES>
101-
<root url="jar://D:/Program Files/jdk8/lib/tools.jar!/" />
101+
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/lib/tools.jar!/" />
102102
</CLASSES>
103103
<JAVADOC />
104104
<SOURCES />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.winter.mapper;
2+
3+
import com.winter.model.Role;
4+
5+
public interface RoleMapper {
6+
int deleteByPrimaryKey(Long id);
7+
8+
int insert(Role record);
9+
10+
int insertSelective(Role record);
11+
12+
Role selectByPrimaryKey(Long id);
13+
14+
int updateByPrimaryKeySelective(Role record);
15+
16+
int updateByPrimaryKey(Role record);
17+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.winter.model;
2+
3+
public class Role {
4+
private Long id;
5+
6+
private String name;
7+
8+
private String type;
9+
10+
public Long getId() {
11+
return id;
12+
}
13+
14+
public void setId(Long id) {
15+
this.id = id;
16+
}
17+
18+
public String getName() {
19+
return name;
20+
}
21+
22+
public void setName(String name) {
23+
this.name = name == null ? null : name.trim();
24+
}
25+
26+
public String getType() {
27+
return type;
28+
}
29+
30+
public void setType(String type) {
31+
this.type = type == null ? null : type.trim();
32+
}
33+
}

src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ server:
44
spring:
55
datasource:
66
name: test
7-
url: jdbc:mysql://127.0.0.1:3306/mytest
7+
url: jdbc:mysql://127.0.0.1:3306/mytest?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
88
username: root
99
password: root
1010
# 使用druid数据源

src/main/resources/generator/generatorConfig.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
55
<generatorConfiguration>
66
<!-- 数据库驱动:选择你的本地硬盘上面的数据库驱动包-->
7-
<classPathEntry location="E:\developer\mybatis-generator-core-1.3.2\lib\mysql-connector-java-5.1.25-bin.jar"/>
7+
<classPathEntry location="/Users/Winterchen/Downloads/mysql-connector-java-5.1.25.jar"/>
88
<context id="DB2Tables" targetRuntime="MyBatis3">
99
<commentGenerator>
1010
<property name="suppressDate" value="true"/>
@@ -18,16 +18,16 @@
1818
<property name="forceBigDecimals" value="false"/>
1919
</javaTypeResolver>
2020
<!-- 生成模型的包名和位置-->
21-
<javaModelGenerator targetPackage="main.java.com.winter.model" targetProject="src">
21+
<javaModelGenerator targetPackage="com.winter.model" targetProject="src/main/java">
2222
<property name="enableSubPackages" value="true"/>
2323
<property name="trimStrings" value="true"/>
2424
</javaModelGenerator>
2525
<!-- 生成映射文件的包名和位置-->
26-
<sqlMapGenerator targetPackage="main.resources.mapping" targetProject="src">
26+
<sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources">
2727
<property name="enableSubPackages" value="true"/>
2828
</sqlMapGenerator>
2929
<!-- 生成DAO的包名和位置-->
30-
<javaClientGenerator type="XMLMAPPER" targetPackage="main.java.com.winter.mapper" targetProject="src">
30+
<javaClientGenerator type="XMLMAPPER" targetPackage="com.winter.mapper" targetProject="src/main/java">
3131
<property name="enableSubPackages" value="true"/>
3232
</javaClientGenerator>
3333
<!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
Lines changed: 71 additions & 0 deletions
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.winter.mapper.RoleMapper" >
4+
<resultMap id="BaseResultMap" type="com.winter.model.Role" >
5+
<id column="id" property="id" jdbcType="BIGINT" />
6+
<result column="name" property="name" jdbcType="VARCHAR" />
7+
<result column="type" property="type" jdbcType="VARCHAR" />
8+
</resultMap>
9+
<sql id="Base_Column_List" >
10+
id, name, type
11+
</sql>
12+
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
13+
select
14+
<include refid="Base_Column_List" />
15+
from u_role
16+
where id = #{id,jdbcType=BIGINT}
17+
</select>
18+
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
19+
delete from u_role
20+
where id = #{id,jdbcType=BIGINT}
21+
</delete>
22+
<insert id="insert" parameterType="com.winter.model.Role" >
23+
insert into u_role (id, name, type
24+
)
25+
values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}
26+
)
27+
</insert>
28+
<insert id="insertSelective" parameterType="com.winter.model.Role" >
29+
insert into u_role
30+
<trim prefix="(" suffix=")" suffixOverrides="," >
31+
<if test="id != null" >
32+
id,
33+
</if>
34+
<if test="name != null" >
35+
name,
36+
</if>
37+
<if test="type != null" >
38+
type,
39+
</if>
40+
</trim>
41+
<trim prefix="values (" suffix=")" suffixOverrides="," >
42+
<if test="id != null" >
43+
#{id,jdbcType=BIGINT},
44+
</if>
45+
<if test="name != null" >
46+
#{name,jdbcType=VARCHAR},
47+
</if>
48+
<if test="type != null" >
49+
#{type,jdbcType=VARCHAR},
50+
</if>
51+
</trim>
52+
</insert>
53+
<update id="updateByPrimaryKeySelective" parameterType="com.winter.model.Role" >
54+
update u_role
55+
<set >
56+
<if test="name != null" >
57+
name = #{name,jdbcType=VARCHAR},
58+
</if>
59+
<if test="type != null" >
60+
type = #{type,jdbcType=VARCHAR},
61+
</if>
62+
</set>
63+
where id = #{id,jdbcType=BIGINT}
64+
</update>
65+
<update id="updateByPrimaryKey" parameterType="com.winter.model.Role" >
66+
update u_role
67+
set name = #{name,jdbcType=VARCHAR},
68+
type = #{type,jdbcType=VARCHAR}
69+
where id = #{id,jdbcType=BIGINT}
70+
</update>
71+
</mapper>

0 commit comments

Comments
 (0)