一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|JavaScript|易語言|

服務器之家 - 編程語言 - JAVA教程 - Spring和MyBatis整合自動生成代碼里面text類型遇到的坑

Spring和MyBatis整合自動生成代碼里面text類型遇到的坑

2021-03-22 13:48OnyWang JAVA教程

Spring和MyBatis整合以后,使用自動生成代碼工具生成dao和mapper配置文件。下面通過本文給大家介紹Spring和MyBatis整合自動生成代碼里面text類型遇到的坑,需要的朋友參考下吧

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運行命令。

Spring和MyBatis整合自動生成代碼里面text類型遇到的坑

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類型遇到的坑,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!

原文鏈接:https://www.jianshu.com/

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 久久香蕉国产免费天天 | 国产日韩欧美色视频色在线观看 | xxxx野外性xxxx| 国产午夜大片 | 日本视频免费在线观看 | 变态np虐高h | 深夜在线影院 | 男人躁女人过程 | 亚洲日本在线观看网址 | 成人二区 | 99久久国产综合精品1尤物 | 人性本色| juy_661佐佐木明希在线播放 | 天堂精品高清1区2区3区 | 国产伦码精品一区二区三区 | 国产亚洲精品第一综合另类 | 丝瓜黄瓜茄子西红柿秋葵榴莲 | 国产乱码一卡二卡3卡四卡 国产乱插 | 女人麻豆国产香蕉久久精品 | 不知火舞被c视频在线播放 不卡一区二区三区卡 | 91碰| 四缺一的小说 | 贰佰麻豆剧果冻传媒一二三区 | 国产网站免费在线观看 | 国产成+人+综合+欧美 亚洲 | 紧身裙女教师miad711在线 | 欧美日韩精品在线观看 | 免费观看二十女人一摸是水 | 日本高清不卡一区久久精品 | 99精品国产成人a∨免费看 | 亚洲 日韩 自拍 视频一区 | 天天操天天干天天 | 亚洲福利区 | 亚洲国产高清一区二区三区 | 全程粗语对白视频videos | ai换脸杨颖被啪在线观看 | 精品国产成人高清在线 | 蜜色网| 朝鲜美女免费一级毛片 | 青涩体验在线观看未删减 | 嗯啊视频在线观看 |