zoukankan      html  css  js  c++  java
  • Mybatis SQL映射文件

    简单查询

    insert添加

     insert可以使用数据库支持的自动生成主键策略,设置useGeneratedKeys=”true”,然后把keyProperty 设成对应的列,就搞定了。比如说上面的StudentEntity 使用auto-generated 为id 列生成主键.
     还可以使用selectKey元素。下面例子,使用mysql数据库nextval('student')为自定义函数,用来生成一个key。

    update修改

    Sql元素用来定义一个可以复用的SQL 语句段,供其它语句调用。比如:

    resultType和resultMap的区别

    1、resultType

    返回单个实例

    <select id="selectUser" parameterType="int" resultType="User">

    select * from user where id = #{id}

    </select>
    返回List集合

    <select id="selectUserAll" resultType="User" > <!-- resultMap="userMap" -->
    select * from user
    </select>

    2、resultMap

    简单查询:

    <resultMap type="User" id="userMap">
    <id column="id" property="id"/>
    <result column="name" property="name"/>
    </resultMap>
    column:数据库中列名称,property:类中属性名称

     

    resultMap:适合使用返回值是自定义实体类的情况

    resultType:适合使用返回值得数据类型是非自定义的,即jdk的提供的类型

    resultMap : 

    映射实体类的数据类型

    resultMap的唯一标识

    column: 库表的字段名

    property: 实体类里的属性名

     

  • 相关阅读:
    Codechef之2014FebChallenge
    Codechef之CodeCraft: IIIT Hyderabad
    原创水题
    用图论模型解决dp问题
    [某模拟赛]一道好题
    萌新java入门笔记
    CodeForces 761C 【DP】
    POJ3268【最短路】
    POJ3191【(-2)进制本质】
    POJ3264 【RMQ基础题—ST-线段树】
  • 原文地址:https://www.cnblogs.com/xuhaifeng017/p/7678060.html
Copyright © 2011-2022 走看看