类似于三个条件,可以全部选择,也可以选择几个条件进行查询

Mapper.xml文件:

<resultMap type="Employee" id="selAll">
<id property="empId" column="empid"/>
<id property="hireDate" column="hiredate"/>
<id property="sex" column="sex"/>
<id property="phone" column="phone"/>
<result property="realName" column="realname"/> <collection property="mgr" ofType="employee">
<id property="empId" column="mgrid"/>
<result property="realName" column="name"/>
</collection> <collection property="position" ofType="position">
<id property="posid" column="posid"/>
<result property="pname" column="pname"/>
</collection> <collection property="dept" ofType="Department">
<id property="deptno" column="deptno"/>
<result property="deptname" column="deptname"/>
</collection>
</resultMap>
<select id="selbyd" resultMap="selAll">
select e.empid,e.realname,e.sex,e.hiredate,e.phone,d.deptname,p.pname,e2.realname
from employee e left join dept d on e.deptno=d.deptno
left join position p on e.posid=p.posid
left join employee e2 on e.mgrid=e2.empid
<where>
and e.onduty=#{onduty}
<if test="deptno!=0">
and d.deptno=#{deptno}
</if> <if test="empid!=null and empid!=''">
<bind name="empid" value="'%'+ empid +'%'"/>
and e.empid like #{empid}
</if>
<if test="hiredate!=null and hiredate!=''">
and e.hiredate &gt;=#{hiredate}
</if>
</where>
</select>

中间用到了模糊查询。

Mapper接口:

List<Employee> selbyd(@Param("empid") String empid,@Param("deptno") int deptno,@Param("hiredate") Date hiredate,@Param("onduty") int onduty);

Service方法:

	List<Employee> selbyd(String empid, int deptno, Date hiredate, int onduty);

ServiceImpl:

@Override
public List<Employee> selbyd(String empid,int deptno, Date hiredate,
int onduty) {
List<Employee> selbyd = mapper.selbyd(empid, deptno, hiredate, onduty);
session.close();
return selbyd;
}

Servlet:

public void selinfo(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String empid = request.getParameter("empId");
int deptno =Integer.parseInt(request.getParameter("deptno"));
String shireDate = request.getParameter("hireDate");
int onduty =Integer.parseInt(request.getParameter("onDuty"));
DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
Date hiredate =null;
try {
hiredate = df.parse(shireDate); } catch (ParseException e) {
System.out.println("");
}
//获取所有的部门信息
DepartmentService ds=new DepartmentServiceImpl();
List<Department> deptList = ds.seAll();
request.setAttribute("deptList", deptList);
EmployeeService es = new EmployeeServiceImpl();
List<Employee> selAll = es.selbyd(empid, deptno, hiredate, onduty);
request.setAttribute("empid", empid);
request.setAttribute("deptno", deptno);
request.setAttribute("onduty", onduty);
request.setAttribute("hireDate", shireDate);
request.setAttribute("selAll", selAll);
request.getRequestDispatcher("/system/empList.jsp").forward(request, response); }

查询所有:

条件查询:

OA项目之mybatis动态查询的更多相关文章

  1. Mybatis动态查询语句

    MyBatis中动态SQL语句完成多条件查询 标签: mybatis动态SQL多条件查询java.sql.SQLSyntaxEr 2015-06-29 19:00 22380人阅读 评论(0) 收藏  ...

  2. Mybatis动态查询

    需要导入的jar包: 实体类User: package com.bjsxt.pojo; import java.io.Serializable; public class User implement ...

  3. SQL mybatis动态查询小结

    动态返回mysql某张表指定列的名字 <select id="queryColumns" resultType="map" parameterType=& ...

  4. OA项目之Mybatis多表链接查询

    xml文件: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC & ...

  5. Java高级架构师(一)第16节:Mybatis动态查询和Json自动拼装

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  6. 在MyBatis中查询数据、涉及多参数的数据访问操作、插入数据时获取数据自增长的id、关联表查询操作、动态SQL、关于配置MyBatis映射没有代码提示的解决方案

    1. 单元测试 在单元测试中,每个测试方法都需要执行相同的前置代码和后置代码,则可以自定义2个方法,分别在这2个方法中执行前置代码和后置代码,并为这2个方法添加@Before和@After注解,然后, ...

  7. mybatis 动态SQL查询总结

    背景 ××项目需要提供系统部分函数第三方调用接口,基于安全性和避免暴露数据库表信息的基础上进行函数接口的设计,根据第三方调用身份的权限提供某张表的自定义集合.本项目基于mybatis的持久层框架,支持 ...

  8. mybatis深入之动态查询和连接池介绍

    mybatis深入之动态查询和连接池介绍 一.mybatis条件查询 在mybatis前述案例中,我们的查询条件都是确定的.但在实际使用的时候,我们的查询条件有可能是动态变化的.例如,查询参数为一个u ...

  9. 项目一:第十三天 1、菜单数据管理 2、权限数据管理 3、角色数据管理 4、用户数据管理 5、在realm中动态查询用户权限,角色 6、Shiro中整合ehcache缓存权限数据

    1 课程计划 菜单数据管理 权限数据管理 角色数据管理 用户数据管理 在realm中动态查询用户权限,角色 Shiro中整合ehcache缓存权限数据         2 菜单数据添加 2.1 使用c ...

随机推荐

  1. 常用样式积累-scss

    /** * author ctj -- 自定义公用样式 */ /*清除浮动*/ .clearfix:after { height:; content: ''; display: block; clea ...

  2. 关于Struts.xml的路径配置以及对应的连接路径问题

    主要记住一点!: 1.   namespace的路径配置例如:/x:   2.  name名自由配置(主要用来是做action跳转方法用的) 3.  form表单中提交action时以这个格式提交(此 ...

  3. 基于docker实现redis高可用集群

    基于docker实现redis高可用集群 yls 2019-9-20 简介 基于docker和docker-compose 使用redis集群和sentinel集群,达到redis高可用,为缓存做铺垫 ...

  4. VS 使用 :新建项目

    1.文件位置不放C盘

  5. Ocelot学习笔记

    最近因工作需要,开始学习Ocelot.首先简单介绍一下,Ocelot是一个基于.net core的开源webapi 服务网关项目,目前已经支持了IdentityServer认证.根据 作者介绍,Oce ...

  6. 正则表达式 第五篇:C# 正则元字符

    本文整理C#正则表达式的元字符,正则表达式是由字符构成的表达式,每个字符代表一个规则,表达式中的字符分为两种类型:普通字符和元字符.普通字符是指字面含义不变的字符,按照完全匹配的方式匹配文本,而元字符 ...

  7. C语言|博客作业01

    2.1你对计算机科学与技术的了解是怎样? 一开始,我并不知道计科和软件的区别,甚至以为这是一种专业的两种叫法.进了大学之后,才一下子懂了,计科就是计科,它和软件虽有相同之处,但是终究是不一样的.计科涉 ...

  8. 防火墙和SELinux复习02

    1.防火墙 防火墙主要起隔离作用,严格的过滤入站,允许出站.又分为硬件防火墙和软件防火墙,硬件防火墙主要保护一群机器,而软件防火墙主要保护本机. 防火墙相关命令:systemctl status fi ...

  9. 2019-9-11:渗透测试,基础学习,vim编辑器,笔记

    Linux快捷路径符号说明. 代表当前目录.. 上级目录- 代表前一个工作目录~ 表示当前用户的家目录 vmware tools 用来虚拟机和宿主机之间移动数据 vim/vi编辑器vim编辑器三种模式 ...

  10. vue防抖节流之v-debounce--throttle使用指南

    最新封装了一个vue防抖节流自定义指令,发布到npm上,有用欢迎star,谢谢! npm地址:https://www.npmjs.com/package/v-debounce-throttle git ...