<?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标签开始,由/mapper结束,可以把它想成一个空间,是映射文件
属性namespace:空间名,主要在代理中使用。这个namespace是唯一的。
这里把mapper标签和接口联系在一起了,namespace=写接口路径,映射文件要和接口在同一目录下
-->
<mapper namespace="com.dao.UserinfoDAO">
<!-- =============映射关系标签=============
属性type:写po类的包名类名,由于之前定义了po类的别名,这里就写这个别名
属性id:是这个映射标签的唯一标识
id标签是查询结果集中的唯一标识
属性column:查询出来的列名
属性property:是po类里所指定的列名
通常会在原列名后面加下划线,这是固定的,这里就是id后面_
-->
<resultMap type="com.po.UserinfoPO" id="userinfoMap">
<result column="userid" property="userid"/>
<result column="loginname" property="loginname"/>
<result column="loginpass" property="loginpass"/>
<result column="username" property="username"/>
<result column="upower" property="upower"/>
<result column="birthday" property="birthday"/>
<result column="sex" property="sex"/>
</resultMap>
<!-- ==================定义sql片段==============
sql:是sql片段标签属性id是该片段的唯一标识 -->
<sql id="zd">
userid,loginname,loginpass,username,upower,birthday,sex
</sql>
<!-- 增删改查标签里的id:一定要和接口里对应的方法名一致,
resultMap输出类型里写映射标签里的id
parameterType:输入类型,规范输入数据类型,指明查询时使用的参数类型-->
<!-- 验证登录 -->
<select id="login" resultMap="userinfoMap" parameterType="com.po.UserinfoPO">
<!-- 用include标签引入sql片段,refid写定义sql片段的id,where标签不要写在片段里 -->
select <include refid="zd"/> from userinfo
<where>
loginname=#{loginname} and loginpass=#{loginpass}
</where>
</select> <!-- 查询用户列表 -->
<select id="userList" resultMap="userinfoMap" parameterType="com.po.UserinfoPO">
<!-- 用include标签引入sql片段,refid写定义sql片段的id,where标签不要写在片段里 -->
select <include refid="zd"/> from userinfo
</select> <!-- 查询修改用户信息的id -->
<select id="updateid" resultMap="userinfoMap" parameterType="com.po.UserinfoPO">
<!-- 用include标签引入sql片段,refid写定义sql片段的id,where标签不要写在片段里 -->
select <include refid="zd"/> from userinfo
<where>userid=#{userid}</where>
</select> <!-- 修改用户信息 -->
<update id="update" parameterType="com.po.UserinfoPO">
update userinfo
set loginname=#{loginname},loginpass=#{loginpass},username=#{username},
upower=#{upower},birthday=#{birthday},sex=#{sex}
where userid=#{userid}
</update> <!-- 添加用户信息 -->
<insert id="insert" parameterType="com.po.UserinfoPO">
insert into userinfo(<include refid="zd"/>)
values
(#{userid},#{loginname},#{loginpass},#{username},#{upower},#{birthday},#{sex})
</insert> <!-- 增删改查标签里的id:一定要和接口里对应的方法名一致 -->
<delete id="delete" parameterType="int">
delete from userinfo where userid=#{userid}
</delete> <!-- 根据用户名模糊查询,根据权限查询 -->
<select id="select" resultMap="userinfoMap" parameterType="java.util.Map">
<!-- 用include标签引入sql片段,refid写定义sql片段的id,where标签不要写在片段里 -->
select <include refid="zd"/> from userinfo
<!-- 当页面没有输入用户名和选择权限,就让它的条件永远为真,就变成全查询了 -->
<where>
<if test="username == null and username = '' and upower == -1">
and 1=1
</if>
<if test="username != null and username !=''">
and username LIKE '%${username}%'
</if>
<if test="upower != -1">
and upower=#{upower}
</if>
</where>
</select>
</mapper>

后续-----

SSM框架中的Mapper.xml文件中的增、删、改、查等操作的更多相关文章

  1. (转)MyBatis框架的学习(四)——Mapper.xml文件中的输入和输出映射以及动态sql

    http://blog.csdn.net/yerenyuan_pku/article/details/71893689 前面对MyBatis框架的学习中,我们对Mapper.xml映射文件多少有些了解 ...

  2. MyBatis Mapper.xml文件中 $和#的区别

    MyBatis Mapper.xml文件中 $和#的区别   网上有很多,总之,简略的写一下,作为备忘.例子中假设参数名为 paramName,类型为 VARCHAR . 1.优先使用#{paramN ...

  3. maven工程中防止mapper.xml文件被漏掉、未加载的方法

    maven工程中防止mapper.xml文件被漏掉.未加载的方法 就是在pom.xml文件中添加以下内容 <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉. --&g ...

  4. mapper.xml文件中传入list参数报错 ‘ ’附近有语法错误

    mapper.xml文件中传入list参数,使用foreach循环遍历值,但是在遍历的过程中出错了,具体代码如下所示 mapper.xml <select id="selectByCo ...

  5. mybatis中的map.xml文件中sql语句需要分号吗?

    mybatis中的map.xml文件中sql语句需要分号吗? :你是说sql介绍的分号吗?不需要的

  6. mapper.xml文件中标签没有提示的解决

    1.首先我们来看看mapper.xml的头文件 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTY ...

  7. Spring MVC框架下在java代码中访问applicationContext.xml文件中配置的文件(可以用于读取配置文件内容)

    <bean id="propertyConfigurer" class="com.****.framework.core.SpringPropertiesUtil& ...

  8. eclipse 中忽略jsp, xml文件中的报错信息

    有的时候, 在eclipse中, jsp, xml 文件时运行的好好的, 可是就是在eclipse中报错, 虽然不影响功能, 但看起来很烦, 去掉这些错误警告的方法是: Windows-Prefere ...

  9. 【转】Android 增,删,改,查 通讯录中的联系人

    一.权限 操作通讯录必须在AndroidManifest.xml中先添加2个权限, <uses-permission android:name="android.permission. ...

随机推荐

  1. 微信小程序:undefined Expecting 'STRING', got INVALID

    出现问题: 问题原因:app.json中不能出现注释

  2. intellij idea如何将web项目打成war包

    1.点击[File]->[Project Structure]菜单(或使用Shift+Ctrl+Alt+S快捷键),打开[Project Structure]窗口.如下图: 2.在[Projec ...

  3. 【C# in depth 第三版】温故而知新(1) (转)

    声明 本文欢迎转载,原文地址:http://www.cnblogs.com/DjlNet/p/7192354.html 前言 关于这本书(<深入理解C# 第三版>)的详细情况以及好坏,自行 ...

  4. Masonry创建Label,不设置高度Label不显示问题

    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(weanSelf).off ...

  5. jenkins配置jdk、git、maven

    进入首页->系统管理->全局工具配置 配置jdk 查找jdk安装路径 如果是容器版jenkins,就登进容器里面查看jdk路径 [root@test2 ~]# echo $JAVA_HOM ...

  6. 【笔记】7天玩转容器&CKA管理员实训

    第一部分 day1,容器基础知识介绍 安装 apt-get install docker-engine [root@cce-7day-fudonghai-24106 01CNL]# docker -v ...

  7. 【Hadoop】MapReduce练习:分科目等级并按分区统计学生以及人数

    需求 ​ 背景:学校的学生的是一个非常大的生成数据的集体,比如每次考试的成绩 ​ 现有一个班级的学生一个月的考试成绩数据. ​ 科目 姓名 分数 ​ 需求:求出每门成绩中属于甲级的学生人数和总人数 ​ ...

  8. python字典操作+文件操作+函数

    师从百测besttest今天老牛教了些函数调用的知识,布置了个作业如下: # 1.写一个商品管理的小程序# 2.商品存在文件里面# 1.添加商品# 输入产品名称.颜色.价格# 要校验商品是否存在,价格 ...

  9. 【图象处理】图文详解YUV420数据格式

    转载自: http://www.cnblogs.com/azraelly/archive/2013/01/01/2841269.html YUV格式有两大类:planar和packed. 对于plan ...

  10. elasticsearch 7.1 401 Unauthorized

    1.执行curl -XGET 'localhost:9200/_cat/indices?v&pretty'  报401 2.修改配置xpack.security.enabled: false ...