标签:语句 文件 映射 resultMap SQL where id select
SQL映射文件的几个顶级元素的配置
mapper:映射文件的根节点
cache:配置给定命名空间的缓存
cache-ref:从其他命名空间引用缓存配置
resultMap:用来描述数据库结果集和对象的对应关系
sql:可以重用的SQL块,也可以被其他语句引用
insert:映射插入语句
update:映射更新语句
delete:映射删除语句
select:映射查询语句
<?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"> <!--namespace需要指向接口全路径--> <mapper namespace="com.wdksuper.dao.userDao"> <!--自动映射--> <resultMap id="userselect" type="smbms_user"> <id property="id" column="id"/> <result property="phones" column="phone"/> </resultMap> <!--id代表当前命名空间下(接口下)的唯一方法名 resultType代表返回值类型--> <select id="selectpwd" resultType="smbms_user"> select * from smbms_user where userCode=#{userCode} </select> <!--查询所有手动映射--> <select id="select" resultMap="userselect"> select * from smbms_user </select> <!--多条件模糊查询--> <select id="selectqwe" resultType="smbms_user"> select * from smbms_user where userName like concat('%',#{userName},'%') and address like concat('%',#{address},'%') </select> <update id="updatepwd"> UPDATE smbms_user set userPassword=#{userPassword} where id=#{id} </update> </mapper>
select(模糊查询语句)
<select id="selectstu" resuleType="Student" paramterType="String">
select * from Student where stuName like CONCAT ('%',#{stuName},'%')
</select>
这是一个id为selectstu的映射查询语句,返回值类型Student,参数类型String
多条件查询
Map<String,String> stuMap=new HashMap<String,String>();
stuMap.put("stuname","赵");
stuMap.put("stuPole","3");
DAO层
public List<Student> stuMaplist(Map(String,String) stumap);
stuMapper.xml
<select id="selectstu" resultType="Studnet" paramterType="Map">
select * from Student where stuName like CONCAT ('%',#{stuName},'%')
and stuRole=#{stuRole}
</select>
resuleMap完成查询结果展示
<resultMap type="Studnet" id="stuList">
<resule property="id" colume="id"/>
<resule property="stuName" colume="stuName"/>
</resuleMap>
id:唯一标识
type:表示resuleMap映射节国类型
result:数据库查询的字段名
property:查询出的结果赋值给实体对象指定的属性
resultType与resultMap
resultType:直接返回值类型,包括基本数据类型和复杂数据类型
resultMap:对外部resultMap定义的引用,对应外部的resultMap的id,表示返回结果映射到哪一个resultMap上
标签:语句,文件,映射,resultMap,SQL,where,id,select 来源: https://www.cnblogs.com/whtt/p/11633780.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。