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>

  • 相关阅读:
    logback-spring.xml配置文件详解
    SpringBoot-Controller接收参数的几种常用方式
    spring boot配置定时任务设置
    SpringCloud 配置文件 application.yml和 bootstrap.yml区别
    ajax/get请求
    ajax封装2
    ajax封装1
    楼层特效
    旋转动画
    联动动画
  • 原文地址:https://www.cnblogs.com/b-dong/p/5985788.html
Copyright © 2011-2022 走看看