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

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. (C#)WPF:LinearGradientBrush 线性渐变画刷和RadialGradientBrush 圆形渐变画刷

    <Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/200 ...

  2. Flsk&pyecharts 动态数据可视化

    1:数据源 Hollywood Movie Dataset: 好莱坞2006-2011数据集  实验目的: 实现 统计2006-2011的数据综合统计情况,进行数据可视化 gitee地址: https ...

  3. JS三座大山再学习(二、作用域和闭包)

    原文地址 作用域 JS中有两种作用域:全局作用域|局部作用域 栗子1 console.log(name); //undefined var name = '波妞'; var like = '宗介' c ...

  4. react-router重定向

    ① ②通过this.props重定向

  5. c++中实现单例模式singleton class

    本文首发于个人博客https://kezunlin.me/post/8932eaec/,欢迎阅读! singleton class and usage in c++. Guide what singl ...

  6. Mac usr/bin 目录 权限问题

    Mac进行 usr/bin 目录下修改权限问题,operation not permitted 一般情况下我们在使用mac系统过程中下载一些文件.新建一些项目之后,这些文件都会默认是只读状态,这时我们 ...

  7. 20191107-3 beta week 2/2 Scrum立会报告+燃尽图 02

    此作业要求参见[https://edu.cnblogs.com/campus/nenu/2019fall/homework/9955] 一.小组情况 队名:扛把子 组长:孙晓宇 组员:宋晓丽 梁梦瑶 ...

  8. python基础-面向对象编程之封装、访问限制机制和property

    面向对象编程之封装 封装 定义:将属性和方法一股脑的封装到对象中,使对象可通过"对象."的方式获取或存储数据. 作用:让对象有了"."的机制,存取数据更加方便 ...

  9. OpenStack集成ceph

    openstack组件集成ceph OpenStack集成ceph详细过程可以查看ceph官方文档:ceph document OpenStack Queens版本,1台控制节点controller, ...

  10. Shell - 长 ping 脚本监控网络时延

    生产环境中, 网络时延是一个很重要的指标. 为了方便检查网络时延的大小, 我们可以通过ping命令实现长时间的网络监控. 1 ping 命令的使用 1.1 常用参数 -i: 每次执行ping操作的间隔 ...