mybatis加数据库表

Posted S大好人S

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mybatis加数据库表相关的知识,希望对你有一定的参考价值。

  1. 在数据库中填加新表
  2. 在总配置文件中加入子mapper地址
  3. <?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.nuanshui.heatedloan.credit.dal.mapper.CreditChangeLogMapper" >//注意此处一定要与添加的类一致
        <resultMap id="creditChangeLogInfo" type="com.nuanshui.heatedloan.credit.model.CreditChangeLogInfo" >//注此处model也要与定义处一致
            <id column="id" property="id" typeHandler="idHandler" />
            <result column="user_id" property="userId"  />
            <result column="order_id" property="orderId"/>
            <result column="type" property="type"/>
            <result column="original_credit" property="originalCredit"/>
            <result column="new_credit" property="newCredit"/>
            <result column="log" property="log"/>
            <result column="created_at" property="createdAt" jdbcType="TIMESTAMP" />
            <result column="updated_at" property="updatedAt" jdbcType="TIMESTAMP" />
        </resultMap>
    
        <insert id="batchInsertCreditChangeLogList"  parameterType="java.util.List">
            <selectKey resultType="long" keyProperty="idRaw" >
                SELECT LAST_INSERT_ID() AS id
            </selectKey>
            insert into credit_change_log (user_id, order_id, type, original_credit, new_credit, log, created_at, updated_at) values
            <foreach collection="list" item="item" index="index" separator=",">
                (#{item.userId},#{item.orderId},#{item.type},#{item.originalCredit},#{item.newCredit},
                #{item.log},now(),now())
            </foreach>
        </insert>
    
    </mapper>
    

      

以上是关于mybatis加数据库表的主要内容,如果未能解决你的问题,请参考以下文章

mybatis-基于xml的多表查询

mybatis关联配置(一对多配置)

MyBatis多表联查

MyBatis关联查询,表字段相同,resultMap映射问题的解决办法

Mybatis框架第二篇

mybatis多表查询