<?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. layui-简单的登录注册界面【转载】

    register.html 源代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ...

  2. mysql数据库指定ip远程访问

    1.登录 mysql -u root -p 之后输入密码进行登陆 2.权限设置及说明 2.1添加远程ip访问权限 GRANT ALL PRIVILEGES ON *.* TO 'root'@'192. ...

  3. linux定时脚本:删除linux/HDFS上过期文件

    一.定时删除linux上定时的文件 显示20分钟前的文件 -exec ls -l {} \; 删除20分钟前的文件 -exec rm {} \; 显示20天前的文件 -exec ls -l {} \; ...

  4. Pytorch-拼接与拆分

    引言 本篇介绍tensor的拼接与拆分. 拼接与拆分 cat stack split chunk cat numpy中使用concat,在pytorch中使用更加简写的 cat 完成一个拼接 两个向量 ...

  5. Android studio无法发现nexus 5x解决方法

    原因: 没有安装adb interface驱动.   解决方法: 1. 使用Android device manager下载google usb driver. 2. 打开设备管理器,右键带黄色感叹号 ...

  6. OSS上传图片demo

    demo整理来源https://help.aliyun.com/document_detail/32011.html /** * 示例说明 * <p> * HelloOSS是OSS Jav ...

  7. linux硬件驱动

    今天被问到了一个新问题:linux需不需要安装驱动,就像windows装完系统之后需要安装最新驱动一样? 说实话以前真没想过,都是装完系统update一下就直接用了. 谷歌了一下,发现其实也是需要安装 ...

  8. spring 配置参数从配置文件中加载到PropertiesFactoryBean 和配置参数从数据库加载到PropertiesFactoryBean 的实现,及项目中的相关应用

    1.加载.properties文件中的配置参数加载到PropertiesFactoryBean容器中 <bean id="configProperties" class=&q ...

  9. python基础知识(字典)

    创建字典 变量名 = {key:value,.....} zip()    转换为zip对象 空字典 变量名 = {} 变量名 = dict(key = value,....) 创建只有键的字典 fr ...

  10. 【AMAD】cookiecutter-django -- 是一个构建Django项目的脚手架工具

    动机 简介 个人评分 动机 Django内置的命令django-admin startproject其实并不好用,在你上线之前八成已经把它改的面目全非了. 简介 cookiecutter-django ...