码迷,mamicode.com
首页 > 数据库 > 详细

mybatis高级(2)_数据库中的列和实体类不匹配时的两种解决方法_模糊查询_只能标签

时间:2016-12-19 11:35:31      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:高级   XML   doctype   oct   data   oracle   type   map   property   

 

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.cnsdhzzl.dao.StudentDao">

    <!-- 当数据库中的列和实体类不匹配时,方法一使用resultMapper -->
    <resultMap type="student" id="studentMapper">
        <!-- 数据库中的列,实体类的属性 -->
        <result column="dataName" property="entityName" />
    </resultMap>
    <!-- 当数据库中的列和实体类不匹配时,方法二语句中使用as,数据库中的列 as 实体类的属性 -->

    <!-- 返回集合要加resultType -->
    <select id="findStudent" resultType="student">
        select * from student
    </select>

    <!-- sql语句区分数据库,以下使用oracle数据库拼接语句使用|| -->

    <!-- 传入map集合时参数需要使用map的key -->
    <select id="likeStudent" resultType="student">
        <!-- 传入map -->
        select * from student where name like ‘%‘||#{mname}||‘%‘ and address
        like ‘%‘||#{maddress}||‘%‘
        <!-- 传入零散参数 -->
        <!-- select * from student where name like ‘%‘||#{0}||‘%‘ and address like 
            ‘%‘||#{1}||‘%‘ -->
    </select>

    <!-- 智能标签 -->
    <select id="smartTag" resultType="student">
        select * from student
        <if test="name !=null">
            and name like ‘%‘||#{name}||‘%‘
        </if>
        <if test="address !=null">
            and address like ‘%‘||#{address}||‘%‘
        </if>
    </select>
</mapper>

 

mybatis高级(2)_数据库中的列和实体类不匹配时的两种解决方法_模糊查询_只能标签

标签:高级   XML   doctype   oct   data   oracle   type   map   property   

原文地址:http://www.cnblogs.com/cnsdhzzl/p/6196518.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!