OA项目之mybatis动态查询

类似于三个条件,可以全部选择,也可以选择几个条件进行查询
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 >=#{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动态查询的更多相关文章
- Mybatis动态查询语句
MyBatis中动态SQL语句完成多条件查询 标签: mybatis动态SQL多条件查询java.sql.SQLSyntaxEr 2015-06-29 19:00 22380人阅读 评论(0) 收藏 ...
- Mybatis动态查询
需要导入的jar包: 实体类User: package com.bjsxt.pojo; import java.io.Serializable; public class User implement ...
- SQL mybatis动态查询小结
动态返回mysql某张表指定列的名字 <select id="queryColumns" resultType="map" parameterType=& ...
- OA项目之Mybatis多表链接查询
xml文件: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC & ...
- Java高级架构师(一)第16节:Mybatis动态查询和Json自动拼装
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...
- 在MyBatis中查询数据、涉及多参数的数据访问操作、插入数据时获取数据自增长的id、关联表查询操作、动态SQL、关于配置MyBatis映射没有代码提示的解决方案
1. 单元测试 在单元测试中,每个测试方法都需要执行相同的前置代码和后置代码,则可以自定义2个方法,分别在这2个方法中执行前置代码和后置代码,并为这2个方法添加@Before和@After注解,然后, ...
- mybatis 动态SQL查询总结
背景 ××项目需要提供系统部分函数第三方调用接口,基于安全性和避免暴露数据库表信息的基础上进行函数接口的设计,根据第三方调用身份的权限提供某张表的自定义集合.本项目基于mybatis的持久层框架,支持 ...
- mybatis深入之动态查询和连接池介绍
mybatis深入之动态查询和连接池介绍 一.mybatis条件查询 在mybatis前述案例中,我们的查询条件都是确定的.但在实际使用的时候,我们的查询条件有可能是动态变化的.例如,查询参数为一个u ...
- 项目一:第十三天 1、菜单数据管理 2、权限数据管理 3、角色数据管理 4、用户数据管理 5、在realm中动态查询用户权限,角色 6、Shiro中整合ehcache缓存权限数据
1 课程计划 菜单数据管理 权限数据管理 角色数据管理 用户数据管理 在realm中动态查询用户权限,角色 Shiro中整合ehcache缓存权限数据 2 菜单数据添加 2.1 使用c ...
随机推荐
- [LINQ2Dapper]最完整Dapper To Linq框架(三)---实体类关系映射
此特性需要安装Kogel.Dapper.Mssql或者Oracle 3.06及以上版本,实体类层需要安装Kogel.Dapper.Extension 3.06及以上版本 目录 [LINQ2Dapper ...
- C# Web分页功能实现
无论是网站还是APP分页功能都是必不可少的.为什么使用分页呢? 1,加载速度快,不会占用服务器太多资源,减少服务器压力. 2,减少数据库压力. 3,提升用户体验. 那么我们常用的分页方法有两种. 1, ...
- nyoj 214-单调递增子序列(二) (演算法,PS:普通的动态规划要超时)
214-单调递增子序列(二) 内存限制:64MB 时间限制:1000ms Special Judge: No accepted:11 submit:35 题目描述: 给定一整型数列{a1,a2..., ...
- nyoj 217-a letter and a number (char)
217-a letter and a number 内存限制:64MB 时间限制:3000ms 特判: No 通过数:4 提交数:5 难度:1 题目描述: we define f(A) = 1, f( ...
- 从最近面试聊聊我所感受的.net天花板
#0 前言 入职新公司没多久,闲来无事在博客园闲逛,看到园友分享的面试经历,正好自己这段时间面试找工作,也挺多感想的,干脆趁这个机会总结整理一下.博主13年开始实习,14年毕业.到现在也工作五六年了. ...
- 力扣(LeetCode)Excel表列序号 个人题解
给定一个Excel表格中的列名称,返回其相应的列序号. 例如, A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ...
- 微调(Fine-tune)原理
在自己的数据集上训练一个新的深度学习模型时,一般采取在预训练好的模型上进行微调的方法.什么是微调?这里已VGG16为例进行讲解,下面贴出VGGNet结构示意图. 上面圈出来的是VGG16示意图,也可以 ...
- 网站统计IP PV UV
###我只是一个搬运工 网站流量统计可以帮助我们分析网站的访问和广告来访等数据,里面包含很多数据的,比如访问使用的系统,浏览器,ip归属地,访问时间,搜索引擎来源,广告效果等. PV(访问量):Pag ...
- GeoServer 查询sql视图
说明: 最近项目中遇到一个需求,需要统计管网的长度,但管网数据量非常大,前端用openlayers接口统计直接就奔溃了. 后尝试使用调后台接口查数据库的方式,虽然可行但是又要多一层与后台交互的工作. ...
- 【Luogu P1164】小A点菜
题目原链接: Luogu 小A点菜 [解题思路] 常规的0-1背包,不过是求装满整个背包的方案数,只要把0-1背包的状态转移方程稍微改一下就行.因为要求方案数,那么把方程中的max换成sum就行. [ ...