XML文件的标头

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.alibaba.我的项目.mapper.XXXXXMapper">


</mapper>

resultMap标签 对象映射

    <resultMap id="BaseResultMap001" type="com.alibaba.项目名.pojo.XXX">
        <!--@mbg.generated-->
        <!--@Table 这里是注释 你可以不写,这里是表明映射的字段-->
        <id column="wallet_id" jdbcType="INTEGER" property="walletId"/>
        <result column="user_account" jdbcType="VARCHAR" property="userAccount"/>
        <result column="green_num" jdbcType="INTEGER" property="greenNum"/>
        <result column="purple_num" jdbcType="INTEGER" property="purpleNum"/>
        <result column="yuanbao_num" jdbcType="INTEGER" property="yuanbaoNum"/>
        <result column="zhendou_num" jdbcType="INTEGER" property="zhendouNum"/>
    </resultMap>

使用方式
    <select id="findOneInfo" resultMap="BaseResultMap001">
 
    </select>

sql 标签 常用于

    <sql id="mysqlList">
        <!--@mbg.generated-->
        wallet_id, user_account, green_num, purple_num, yuanbao_num, zhendou_num
    </sql>

使用:

    <select id="findOneInfo">
        select <include refid="mysqlList"/> from
    </select>
    

插入数据返回主键 返回到插入的对象中

 Mapper层 有无返回值 都行,反正的主键在对象中!

 useGeneratedKeys 开启主键插入到对象中
 keyProperty 实体类的属性名
 <insert id="initUserLook" useGeneratedKeys="true" keyProperty="id">

还有一个模板,是mybatisCodeHelper生成的,还有待研究!

<?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="/Program Files/IBM/SQLLIB/java/db2java.zip" />-->

    <context id="Mybatis3Context" targetRuntime="MyBatis3">
        <property name="javaFileEncoding" value="UTF-8"/>
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/MyBatisCodeHelper?useLegacyDatetimeCode=false&amp;serverTimezone=UTC&amp;nullCatalogMeansCurrent=true"
                        userId="root"
                        password="">
        </jdbcConnection>

        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <javaModelGenerator targetPackage="model" targetProject="D:/代码/RedEnvelop/src/main/java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="mapperxml" targetProject="D:/代码/RedEnvelop/src/main/resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>

        <javaClientGenerator type="XMLMAPPER" targetPackage="mapper" targetProject="D:/代码/RedEnvelop/src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <table tableName="Customer" domainObjectName="Customer" enableCountByExample="false"
               enableDeleteByExample="false" enableUpdateByExample="false" enableSelectByExample="false">
        </table>

    </context>
</generatorConfiguration>
特殊说明:
上述文章均是作者实际操作后产出。烦请各位,请勿直接盗用!转载记得标注原文链接:www.zanglikun.com
第三方平台不会及时更新本文最新内容。如果发现本文资料不全,可访问本人的Java博客搜索:标题关键字。以获取全部资料 ❤