After Spring and MyBatis are integrated, the dao and mapper configuration files are generated using the automatic code generation tool. The generation steps are as follows (taking Intelli idea as an example).
1. Write the generated code configuration file generatorConfig.xml.
<?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"/> <!-- Whether to remove the automatically generated comments true: Yes: false: No--> <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> <!-- Generate model package name and location--> <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> <!--Requires automatic generated table name and corresponding model name--> <table tableName="sys_user" domainObjectName="SysUser"></table> </context></generatorConfiguration>
2. Configure the following maven run command.
3. Just run generatorcode.
Problem description
If there is a text or blob field in the database table. The automatically generated database configuration file is as follows, and there will be several additional methods and resultMap ending withBlobs:
<!-- Just post different parts--><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>If you use selectByExample or updateByExample in this way, the text or blob data obtained is null.
The correct way to do it
You should use the two methods: selectByExampleWithBLOBs or updateByExampleWithBLOBs.
Summarize
The above is the pitfalls encountered by the text type in the integration of Spring and MyBatis automatic generation code that the editor introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!