Spring and MyBatis are integrated to automatically generate text-type traps in the Code. springmybatis
After the integration of Spring and MyBatis, use the Automatic Generation Code tool to generate the dao and mapper configuration files. The generation steps are as follows (taking Intelli idea as an example ).
1. Compile 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-connector-java \ 5.1.39 \ mysql-connector-java-5.1.39.jar "/> <context id =" DB2Tables "defaultModelType =" flat "targetRuntime =" MyBatis3 "> <commentGenerator> <prope Rty name = "suppressDate" value = "true"/> <! -- Whether to remove 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 the 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> <! -- Automatically generated table name and corresponding model name --> <table tableName = "sys_user" domainObjectName = "SysUser"> </table> </context> </generatorConfiguration>
2. Configure the following maven running command.
3. Run generatorcode.
Problem description
Assume that text or blob fields exist in the database table. The automatically generated database configuration file is as follows. Several Methods ending with withBlobs and resultMap will be added:
<! -- Only paste 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 selectByExample or updateByExample is still used to query or update data, the resulting text or blob data is null.
Correct practice
The selectByExampleWithBLOBs or updateByExampleWithBLOBs methods should be used.
Summary
The above is a small part of Spring and MyBatis integrated to automatically generate text types in the code. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!