码迷,mamicode.com
首页 > 数据库 > 详细

mybatis加数据库表

时间:2017-09-21 23:22:35      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:origin   red   tty   dha   model   sep   creat   1.0   3.0   

  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加数据库表

标签:origin   red   tty   dha   model   sep   creat   1.0   3.0   

原文地址:http://www.cnblogs.com/wlemory/p/7571708.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!