E-commerce website Development Record (ii) Introduction of the Three Musketeers of MyBatis

Source: Internet
Author: User

Introduction of the MyBatis Three Musketeers

1.mybatis-generator, create a new generatorconfig.xml under Resources, the configuration file details are as follows

<?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>
<!--Import Property configuration--
<properties resource= "Datasource.properties" ></properties>

<!--Specify the location of the JDBC driver jar package for a specific database--
<classpathentry location= "${db.driverlocation}"/>

<context id= "Default" Targetruntime= "MyBatis3" >

<!--optional, which is designed to control annotations when creating a class-
<commentGenerator>
<property name= "Suppressdate" value= "true"/>
<property name= "Suppressallcomments" value= "true"/>
</commentGenerator>

<!--JDBC Database connection--
<jdbcconnection
driverclass= "${db.driverclassname}"
Connectionurl= "${db.url}"
Userid= "${db.username}"
Password= "${db.password}" >
</jdbcConnection>


<!--not required, type processor, conversion control between database type and Java type--
<javaTypeResolver>
<property name= "Forcebigdecimals" value= "false"/>
</javaTypeResolver>


<!--model Builder to generate classes containing primary key keys, record classes, and query example classes
TARGETPACKAGE Specifies the package name in which the generated model is generated
TARGETPROJECT specifies the path under which the item is located
-
<!--<javamodelgenerator targetpackage= "Com.mmall.pojo" targetproject= ". \src\main\java" >-->
<javamodelgenerator targetpackage= "Com.mall.pojo" targetproject= "./src/main/java" >
<!--whether to allow child packages, i.e. TargetPackage.schemaName.tableName
<property name= "Enablesubpackages" value= "false"/>
<!--If you add a constructor to the model--
<property name= "constructorbased" value= "true"/>
<!--whether to trim data for columns of class char type-
<property name= "Trimstrings" value= "true"/>
< If the model object created by the!--is immutable, the resulting model object will not have setter methods, only construction methods--
<property name= "Immutable" value= "false"/>
</javaModelGenerator>

<!--the mapper map file is generated in the same directory as the table for each database generates the corresponding Sqlmap file--
<!--<sqlmapgenerator targetpackage= "mappers" targetproject= ". \src\main\resources" >-->
<sqlmapgenerator targetpackage= "Mappers" targetproject= "./src/main/resources" >
<property name= "Enablesubpackages" value= "false"/>
</sqlMapGenerator>

<!--client code to generate easy-to-use code for model objects and XML configuration files
Type= "Annotatedmapper" to generate Java Model and annotation-based mapper objects
Type= "Mixedmapper" to generate the annotated Java Model and the corresponding Mapper object
Type= "Xmlmapper", generate Sqlmap XML file and stand-alone mapper interface
-

<!--Targetpackage:mapper Interface DAO generated location--
<!--<javaclientgenerator type= "Xmlmapper" targetpackage= "Com.mall.dao" targetproject= ". \src\main\java" >- -
<javaclientgenerator type= "Xmlmapper" targetpackage= "Com.mall.dao" targetproject= "./src/main/java" >
<!--enablesubpackages: Do you want the schema to be a suffix of the package--
<property name= "Enablesubpackages" value= "false"/>
</javaClientGenerator>


<table tablename= "mmall_shipping" domainobjectname= "Shipping" enablecountbyexample= "false" Enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "False" ></table>
<table tablename= "Mmall_cart" domainobjectname= "cart" enablecountbyexample= "false" enableupdatebyexample= "false "Enabledeletebyexample=" false "enableselectbyexample=" false "Selectbyexamplequeryid=" false "></table>
<table tablename= "Mmall_cart_item" domainobjectname= "Cartitem" enablecountbyexample= "false" Enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "False" ></table>
<table tablename= "mmall_category" domainobjectname= "category" Enablecountbyexample= "false" Enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "False" ></table>
<table tablename= "Mmall_order" domainobjectname= "Order" enablecountbyexample= "false" enableupdatebyexample= " False "enabledeletebyexample=" false "enableselectbyexample=" false "Selectbyexamplequeryid=" false "></table >
<table tablename= "Mmall_order_item" domainobjectname= "OrderItem" enablecountbyexample= "false" Enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "False" ></table>
<table tablename= "Mall_pay_info" domainobjectname= "Payinfo" enablecountbyexample= "false" enableUpdateByExample= "False" enabledeletebyexample= "false" enableselectbyexample= "false" Selectbyexamplequeryid= "false" ></table >
<table tablename= "mmall_product" domainobjectname= "Product" enablecountbyexample= "false" enableupdatebyexample= "False" enabledeletebyexample= "false" enableselectbyexample= "false" Selectbyexamplequeryid= "false" >
<columnoverride column= "Detail" jdbctype= "VARCHAR"/>
<columnoverride column= "Sub_image" jdbctype= "VARCHAR"/>
</table>
<table tablename= "Mmall_user" domainobjectname= "user" enablecountbyexample= "false" enableupdatebyexample= "false "Enabledeletebyexample=" false "enableselectbyexample=" false "Selectbyexamplequeryid=" false "></table>


<!--geelynote MyBatis plug-in construction--
</context>
</generatorConfiguration>
Create a new datasource.properties under Resources, configured as follows:

Db.driverlocation=c:/mysql-connector-java-5.1.6-bin.jar
Db.driverclassname=com.mysql.jdbc.driver
Db.url=jdbc:mysql://127.0.0.1:3306/mmall_learning?characterencoding=utf-8
Db.username=root
Db.password=root

The detail and sub_image are text types, and there is no text type in Jdbctype, which needs to be converted to a varchar type.

Mybatis-generator function, automatically generates DAO,POJO layer, and mappper.

PS: When adding data to the database, it is often added creattime, and UpdateTime, two timestamps, so that the data can be added automatically at the time of adding the two data, to avoid unnecessary errors, the mapper under the XML file under the Insert value change , Creattime and UpdateTime are changed to now (), and the updatetime in update changes to now (). When configured, you can run the plug-in.

2.mybatis-plugin plug-in, install one, restart idea.

Function: Makes the interface of the DAO layer correspond to the XML file one by one of the mapper layer

3.mybatis-pagehelper introduced,

E-commerce website Development Record (ii) Introduction of the Three Musketeers of MyBatis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.