zoukankan      html  css  js  c++  java
  • mybatis笔记(一)

    mybatis

    (一)传值 三种方式

    1.直接传值
    void getMessageList(int userId,String userName);
    mapper.xml 获取 #{0}代表userId #{1}代表userName
    2.设置成键值对
    i)包装成实体信息
    void getMessageList(User user);
    //传入类型为 User
    mapper.xml #{userId} #{userName}
    ii)包装成map
    void getMessageList(Map map);
    //map.put("userId",userId);
    //map.put("userName",userName);
    //传入类型为hashMap

    mapper.xml #{userId} #{userName}
    3.dao成注解(也是包装成map的数据格式 传入类型可以为hashMap)
    void getMessageList(@Param("userId")int userId, @Param("userName")String userName);
    mapper.xml #{userId} #{userName}

    (二)#和&
    #{} 传入的数据默认为字符串,会自动加上双引号
    ${} 传入的数据直接展示到 sql

    #{}可以防止sql注入
    ${}一般传入表名 或 数据为Int型(parameterType没有声明)
    最好都用#{}

    (三)循环

    index:为数组的下标。
    item:为数组每个元素的名称,名称随意定义
    open:循环开始
    close:循环结束
    separator:中间分隔输出

    <foreach collection="ids" open=" and id in(" close=")" item="id" separator="," >
    #{id}
    </foreach>

  • 相关阅读:
    python基础7
    python基础7
    十大经典预测算法(一)----线性回归
    RNN-循环神经网络
    CNN之经典卷积网络框架原理
    卷积神经网络CNN
    决策树的生成
    欠拟合、过拟合及解决方法
    决策树
    KD树
  • 原文地址:https://www.cnblogs.com/b-dong/p/5985788.html
Copyright © 2011-2022 走看看