大型运输行业实战_day04_2_高级查询
1.高级查询最总效果

2.高级查询步骤
2.1页面输入框显示
开始车站:<input id="startStation" type="text" value="" /> 到
到达车站:<input id="stopStation" type="text" value="" />
<button onclick="query()">查询</button>
2.2获取输入参数并发送ajax请求
/* 高级查询js函数*/
function query(){
//alert("------query------");
//1.获取参数
var startStation = $("#startStation").val();
//alert("startStation="+startStation);
var stopStation = $("#stopStation").val();
//2.发送请求
var params = {
startStation:startStation,
stopStation:stopStation
};
var url = 'http://localhost:8080/ticket2/data2';
jQuery.ajax({
type: 'POST',
contentType: 'application/x-www-form-urlencoded',
url: url,
data: params,
dataType: 'json',
success: function (data) {
var html='<tr>'+
'<td>编号</td>'+
'<td>开始车站</td>'+
'<td>到达车站</td>'+
'</tr>';
//解析数据到table表中
for (var i=0;i<data.length;i++){
//取出一个对象
var ticket = data[i];
//java里面的内省机制 取出对象中的值
var id = ticket.id;
var startStation= ticket.startStation;
var stopStation= ticket.stopStation;
//拼接html代码
html+='<tr>'+
'<td>'+id+'</td>'+
'<td>'+startStation+'</td>'+
'<td>'+stopStation+'</td>'+
'</tr>';
}
//3.填充数据
$("#ticketList").html(html);
},
error: function (data) {
alert("失败啦");
}
});
}
2.3控制层处理
/**
* 高级查询获取车票数据
*/
@RequestMapping("/data2")
@ResponseBody //请求数据必须写这个
public List<Ticket> getData2(TicketQueryObj ticketQueryObj){
//接收参数
//调用方法
List<Ticket> list = ticketService.getList(ticketQueryObj);
//控制跳转
return list;
}
2.4业务层处理
@Override
public List<Ticket> getList(TicketQueryObj ticketQueryObj) {
List<Ticket> tickets = ticketDao.queryList(ticketQueryObj);
return tickets;
}
2.5持久层接口
/**
* 根据条件查询
* @param ticketQueryObj
* @return
*/
List<Ticket> queryList(TicketQueryObj ticketQueryObj);
2.6映射文件sql语句
<select id="queryList" parameterType="com.day02.sation.query.TicketQueryObj" resultType="com.day02.sation.model.Ticket">
SELECT id,start_station startStation,stop_station stopStation FROM ticket
<where>
<if test="startStation!=null and startStation!='' ">
AND start_station = #{startStation}
</if>
<if test="stopStation!=null and stopStation!='' ">
AND stop_station=#{stopStation}
</if>
</where>
</select>
2.7测试dao是否可用 注意必须测试
@Test
public void testGetList2(){
TicketQueryObj ticketQueryObj = new TicketQueryObj();
ticketQueryObj.setStartStation("成都 ");
ticketQueryObj.setStopStation("南充");
List<Ticket> list = ticketDao.queryList(ticketQueryObj);
System.out.println("list="+list);
}
2.8.使用到的查询对象TicketQueryObj.java
package com.day02.sation.query; /**
* Created by Administrator on 12/28.
*/
public class TicketQueryObj {
private String startStation;
private String stopStation;
public String getStartStation() {
return startStation;
}
public void setStartStation(String startStation) {
this.startStation = startStation;
}
public String getStopStation() {
return stopStation;
}
public void setStopStation(String stopStation) {
this.stopStation = stopStation;
}
}
TicketQueryObj.java
2.9.重启项目高级查询实现完成!
大型运输行业实战_day04_2_高级查询的更多相关文章
- 大型运输行业实战_day04_3_高级查询+分页
1.高级查询+分页最终结果 2.分页的本质分析 前端传入:当前页 和 每页显示条数 数据库必须查询出:数据列表 和 总共条数 页面显示包括的数据有: 列表 + 每页显示条数 + 当前页 + 总共 ...
- 大型运输行业实战_day11_2_事务理论与实际生产配置事务管理
1.什么是事务(Transaction:tx) 数据库的某些需要分步完成,看做是一个整体(独立的工作单元),不能分割,要么整体成功,要么整体生效.“一荣俱荣,一损俱损”,最能体现事务的思想.案例:银行 ...
- 大型运输行业实战_day09_2_站间互售实现
1.添加站间互售入口 对应的html代码 <button onclick="otherStation()">站间互售</button> 对应的js发送函数 ...
- 大型运输行业实战_day09_1_日期转换与My97DatePicker插件使用
1.日期转换 1.1字符串类型转换成时间Date类型 /** * 给定字符串 转变 为 Date 类型 * @param date 时间 * @param format 时间格式 如:yyyy-MM- ...
- 大型运输行业实战_day07_1_订单查看实现
1.业务分析 每个在窗口售票的售票员都应该可以随时查看自己的售票信息 简单的界面入口如图所示: 对应的html代码: <button onclick="orderDetail()&qu ...
- 大型运输行业实战_day15_1_全文检索之Lucene
1.引入 全文检索简介: 非结构化数据又一种叫法叫全文数据.从全文数据(文本)中进行检索就叫全文检索. 2.数据库搜索的弊端 案例 : select * from product whe ...
- 大型运输行业实战_day14_1_webserivce简单入门
1.简单使用 1.1.服务端 1.编写接口 package com.day02.sation.ws; /** * Created by Administrator on 1/12. */ public ...
- 大型运输行业实战_day12_1_权限管理实现
1.业务分析 权限说的是不同的用户对同一个系统有不同访问权限,其设计的本质是:给先给用户分配好URL,然后在访问的时候判断该用户是否有当前访问的URL. 2.实现 2.1数据库设计标准5表权限结构 2 ...
- 大型运输行业实战_day07_2_数据字典实现
1.数据字典表 CREATE TABLE `dic` ( `id` ) NOT NULL AUTO_INCREMENT, `table_name` ) DEFAULT NULL, `field_nam ...
随机推荐
- protobuf 协议 windows 下 java 环境搭建
使用maven编译protobuf所需要的jar包 1. 安装配置maven (1)下载maven http://maven.apache.org/ 版本:apache-maven ...
- linux 脚本 逻辑关系的写法及区别
今天总结一下linux shell中逻辑关机表达方式. 逻辑与的表达:1).if [ $xxx=a -a $xx=b ] 2).if [ $xxx=a ] && [ $xx=b ]逻 ...
- yum安装软件时报错:Loaded plugins:fastestnirror,security Existing lock /var/run/yum.pid
在linux中使用yum时出现如下错误: Loaded plugins: fastestmirror, security Existing lock /var/run/yum.pid: another ...
- VMware 安装Windows sever 2008 R2服务器
一. 安装包下载: Windows Server 2008 R2 简体中文企业版[server 2008 r2下载] 二. 新建虚拟机 三. 安装Window Server 2008 R2 四. 服务 ...
- [转载]Deep Learning(深度学习)学习笔记整理
转载自:http://blog.csdn.net/zouxy09/article/details/8775360 感谢原作者:zouxy09@qq.com 八.Deep learning训练过程 8. ...
- Spark分析之BlockManager
BlockManager中存储block的流程: doPut()方法 入参:blockId, data, level, tellMaster 1)为block创建BlockInfo并加锁使其不能被 ...
- mysql5.6修改字符编码,ERR:Illegal mix of collations for operation 'concat'
mysql5.6修改字符编码,ERR:Illegal mix of collations for operation 'concat' 1.问题起因:搭建环境初始化mysql的时候看到mysql配置文 ...
- Flask 进阶二
flask中的路由系统: endpoint:反向url地址,默认为视图函数名(url_for). from flask import Flask,url_for app = Flask(__name_ ...
- LaunchFaster 启动器工具 - 类似 Rolan 和音速启动的图标式快捷启动软件
LaunchFaster 启动器是本人近期编写的一款windows平台上快速启动应用的开源工具软件. LaunchFaster 启动器是一款类似于 Rolan 和 音速启动 和 Lily 的图标形式的 ...
- 练习Laravel Homestead的安装
1 安装VirtualBox和Vagrant 在启动Homestead环境之前,你必须安装VirtualBox(https://www.virtualbox.org/wiki/Downloads)和V ...