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>
    

      

posted @ 2017-09-21 22:30  S大好人S  阅读(201)  评论(0编辑  收藏  举报