<?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. Git入门之在IDEA中使用Git上传maven项目

    下载安装git客户端: 参考博文:https://www.cnblogs.com/java-maowei/p/5950930.html 在IDEA怎么使用git上传spring的maven项目详解: ...

  2. C#WinForm程序显示控制台窗口Console

    启动一个WINFORM项目,使用一些API函数将控制台显示出来: AllocConsole 和 FreeConsole. 本程序只在DEBUG模式下显示控制台 [DllImport("ker ...

  3. 一百零七:CMS系统之权限和角色模型定义

    模型与权限关系映射表 class CMSPersmission: """ 权限管理映射 """ # 255的二进制方式来表示 1111 11 ...

  4. python中计时模块timeit的使用方法

    timeit 模块: timeit 模块定义了接受两个参数的 Timer 类.两个参数都是字符串. 第一个参数是你要计时的语句或者函数. 传递给 Timer 的第二个参数是为第一个参数语句构建环境的导 ...

  5. MMORPG服务器架构

    MMORPG服务器架构 一.摘要 1.网络游戏MMORPG整体服务器框架,包括早期,中期,当前的一些主流架构2.网络游戏网络层,包括网络协议,IO模型,网络框架,消息编码等.3.网络游戏的场景管理,A ...

  6. SQL Server 中 ROWLOCK 行级锁

    一.ROWLOCK的使用 1.ROWLOCK行级锁确保,在用户取得被更新的行,到该行进行更新,这段时间内不被其它用户所修改.因而行级锁即可保证数据的一致性,又能提高数据操作的并发性. 2.ROWLOC ...

  7. 微信小程序添加卡券到微信卡包,使用wx.addCard()方法传参及整体流程

    一.准备: 1.经微信认证过的微信公众号. 2.经微信认证过的微信小程序号. 先来看看微信小程序官方的文档,https://developers.weixin.qq.com/miniprogram/d ...

  8. Mybatis 属性配置

    properties  定义配置,配置的属性可以在整个配置文件中的其他位置进行引用 <properties resource="db.properties"></ ...

  9. 【VS开发】【编程开发】【C/C++开发】结构体中的数组与指针的内存分配情况说明

    [VS开发][编程开发][C/C++开发]结构体中的数组与指针的内存分配情况说明 标签:[VS开发] [编程开发] 主要是疑惑在结构体定义的数组的内存空间与指针动态分配的内存空间,在地址上连续性.以及 ...

  10. SQuirreL连接Phoenix报java.util.concurrent.TimeoutException

    1.表象 java.util.concurrent.TimeoutException at java.util.concurrent.FutureTask.get(FutureTask.java:20 ...