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?)
    >
     
  • 相关阅读:
    零基础学python-4.5 标准类型分类
    零基础学python-4.4 常用的一些内建函数
    零基础学python-4.3 对象的比较
    零基础学python-4.2 其他内建类型
    零基础学python-4.1 python对象的简介和标准类型
    7、postman中的Newman插件(可生成html测试报告)
    6、postman cookie和token使用
    5、postman认证方式简单了解
    4、postman动态参数传递(含token详细使用)
    3、postman中tests断言使用
  • 原文地址:https://www.cnblogs.com/Java60-123456/p/10656512.html
Copyright © 2011-2022 走看看