zoukankan      html  css  js  c++  java
  • mybatis 的模糊查询,别名,添加后返回自增列的值,mapper中sql字段的提取 configration节点中子节点顺序

    1.模糊查询:
    <!--方式一-->
    select * from user where userName like '%' #{username} '%' //防止SQL注入
    <!--方式二 oracle数据库用-->
    select * from user  where userName like '%'||#{username}||'%' //防止SQL注入的
    <!--方式三-->
    select * from user  where userName like '%' #{username} '%' //防止SQL注入

     Preparing: select * from user where userName like concat('%',?,'%') //提交时以?提交避免了sql注入(方式1与方式2相同)
     Parameters: 李(String)

    <!--方式四-->
    select * from user  where userName like '%${value}%'  //不能防止SQL注入,而且站位的名称必须为value

    Preparing: select * from user where userName like '%李%' // 提交时与参数一起提交不能防止sql注入
     Parameters:

    2.别名
    <typeAliases>
    <typeAlias type="entity.User" alias="user"></typeAlias>//设置单个实体类的别名 alias:别名
    <package name="entity"></package>//该包下类的简单名称(只有类名,不包括包名)作为别名;
    </typeAliases>
    3.添加后返回自增列的值:
    <insert id="add"  >
    insert into `user` (loginName,password,userName)values(#{loginname},#{password},#{username})
    <selectKey keyProperty="id" resultType="int">
    select @@IDENTITY //用select @@identity得到上一次插入记录时自动产生的ID
    </selectKey>
    </insert>
    4.mapper中sql字段的提取:
    <sql id="clude">username,password</sql>
    <select id="findall" resultType="user">
    select<include refid="clude"></include> from user //refid用于定位映射sql语句重点id
    </select>
    5.configration节点中子节点顺序:否则报错
    <!ELEMENT configuration (
    properties?,
    settings?,
    typeAliases?,
    typeHandlers?,
    objectFactory?,
    objectWrapperFactory?,
    reflectorFactory?,
    plugins?,
    environments?,
    databaseIdProvider?,
    mappers?)
    >
     
  • 相关阅读:
    设计模式之工厂模式-抽象工厂(02)
    1036 跟奥巴马一起编程 (15 分)
    1034 有理数四则运算 (20 分)
    1033 旧键盘打字 (20 分)
    1031 查验身份证 (15 分)
    大学排名定向爬虫
    1030 完美数列 (25 分)二分
    1029 旧键盘 (20 分)
    1028 人口普查 (20 分)
    1026 程序运行时间 (15 分)四舍五入
  • 原文地址:https://www.cnblogs.com/Java60-123456/p/10656512.html
Copyright © 2011-2022 走看看