spring和mybatis整合以后,使用自动生成代码工具生成dao和mapper配置文件,生成步骤如下(以intelli idea为例)。
1.编写生成代码配置文件generatorconfig.xml。
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
<?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="d:\\dev\\maven\\repository\\mysql\\mysql-connector-java\\5.1.39\\mysql-connector-java-5.1.39.jar"/>
<context id="db2tables" defaultmodeltype="flat" targetruntime="mybatis3">
<commentgenerator>
<property name="suppressdate" value="true"/>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressallcomments" value="false"/>
</commentgenerator>
<jdbcconnection driverclass="com.mysql.jdbc.driver"
connectionurl="jdbc:mysql://localhost:3306/mycollege?characterencoding=utf-8"
userid="root"
password="root">
</jdbcconnection>
<javatyperesolver>
<property name="forcebigdecimals" value="false"/>
</javatyperesolver>
<!-- 生成模型的包名和位置 -->
<javamodelgenerator targetpackage="com.cx.elearnning.model"
targetproject="src/main/java">
<property name="enablesubpackages" value="true"/>
<property name="trimstrings" value="true"/>
</javamodelgenerator>
<!-- generate xml -->
<sqlmapgenerator targetpackage="/"
targetproject="src/main/resources/mapper">
<property name="enablesubpackages" value="true"/>
</sqlmapgenerator>
<!-- generate mapper -->
<javaclientgenerator type="xmlmapper" targetpackage="com.cx.elearnning.dao"
targetproject="src/main/java">
<property name="enablesubpackages" value="true"/>
</javaclientgenerator>
<!--需要自动生成的表名和对应的model名-->
<table tablename="sys_user" domainobjectname="sysuser"></table>
</context>
</generatorconfiguration>
|
2.配置如下maven运行命令。
3.运行generatorcode即可。
问题描述
假如数据库表里面存在text或者blob字段。自动生成的数据库配置文件如下,会多出几个以withblobs结尾的方法和resultmap:
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
<!--仅仅贴上不一样的部分-->
<resultmap extends="baseresultmap" id="resultmapwithblobs" type="com.cx.elearnning.model.eduwebsiteprofile">
<!--
warning - @mbggenerated
this element is automatically generated by mybatis generator, do not modify.
-->
<result column="desciption" jdbctype="longvarchar" property="desciption" />
</resultmap>
<select id="selectbyexamplewithblobs" parametertype="com.cx.elearnning.model.eduwebsiteprofileexample" resultmap="resultmapwithblobs">
<!--
warning - @mbggenerated
this element is automatically generated by mybatis generator, do not modify.
-->
select
<if test="distinct">
distinct
</if>
<include refid="base_column_list" />
,
<include refid="blob_column_list" />
from edu_website_profile
<if test="_parameter != null">
<include refid="example_where_clause" />
</if>
<if test="orderbyclause != null">
order by ${orderbyclause}
</if>
</select>
|
假如此时查询数据或者更新数据的使用仍然使用selectbyexample或者updatebyexample,得到的text或者blob数据是null。
正确做法
应该使用selectbyexamplewithblobs或者updatebyexamplewithblobs这两个方法。
总结
以上所述是小编给大家介绍的spring和mybatis整合自动生成代码里面text类型遇到的坑,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对快网idc网站的支持!
原文链接:https://www.jianshu.com/
相关文章
猜你喜欢
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-06-04 72
-
2025-05-29 94
-
2025-05-27 92
-
2025-06-04 39
-
2025-05-27 56
热门评论


