1、界面展示
2、WebContent/jsp/combobox_002.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% String root = request.getContextPath(); %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>【combobox组件】-002-自动搜索案例</title> <!-- 引入外部样式 --> <link rel="stylesheet" type="text/css" href="<%=root %>/css/common.css" /> <!-- 引入easyui依赖库 --> <script type="text/javascript" src="<%=root %>/js/jquery-easyui-1.2.6/jquery-1.7.2.min.js"></script> <link rel="stylesheet" type="text/css" href="<%=root %>/js/jquery-easyui-1.2.6/themes/default/easyui.css" /> <link rel="stylesheet" type="text/css" href="<%=root %>/js/jquery-easyui-1.2.6/themes/icon.css" /> <script type="text/javascript" src="<%=root %>/js/jquery-easyui-1.2.6/jquery.easyui.min.js"></script> <script type="text/javascript" src="<%=root %>/js/jquery-easyui-1.2.6/locale/easyui-lang-zh_CN.js"></script> <script type="text/javascript"> $(function() { //自动搜索 $('#search').combobox({ //data:[{id:1 ,val:'男'},{id:2 ,val:'女'}], //自定义列表数据 mode:'remote', //remote表示从服务器加载数据 url:'<%=root%>/UserServlet?method=searchName', //请求地址 valueField:'id', textField:'username', panelHeight:'auto', delay:300 //延迟搜索的时间 }); }); </script> </head> <body> 自动搜索:<input id="search"/> </body> </html>
3、com.easyui.servlet.UserServlet.java
package com.easyui.servlet; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import com.easyui.bean.CityBean; import com.easyui.bean.TUserBean; import com.easyui.dao.UserDao; /** * 用户控制器类 * * @author LiPiaoShui */ public class UserServlet extends HttpServlet { private static final long serialVersionUID = 9140830946116659042L; private UserDao uDao = new UserDao(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); String method = request.getParameter("method"); if ("getList".equals(method)) { getList(request, response); } else if("getCityName".equals(method)) { getCityName(request, response); } else if("getCity".equals(method)) { getCity(request, response); } else if("save".equals(method)) { save(request, response); } else if("update".equals(method)) { update(request, response); } else if("delete".equals(method)) { delete(request, response); } else if("searchName".equals(method)) { searchName(request, response); } } /** * 根据名字查询用户信息 * @param request * @param response */ private void searchName(HttpServletRequest request, HttpServletResponse response) { try { //默认前台送过来的是p参数 String q = request.getParameter("q") == null ? "" : request.getParameter("q"); List<TUserBean> uList = this.uDao.searchByName(q.trim()); response.setContentType("text/html;charset=utf-8"); response.getWriter().write(JSONArray.fromObject(uList).toString()); } catch (IOException e) { e.printStackTrace(); } } /** * 删除用户信息 * @param request * @param response */ private void delete(HttpServletRequest request, HttpServletResponse response) { try { String[] ids = request.getParameter("ids").split(","); int count = 0; for(String id:ids) { count += this.uDao.deleteByUserId(Integer.parseInt(id)); } String json = "{\"status\":\"提示信息\",\"message\":\"删除成功,总共删除"+count+"条记录\"}"; if(count <= 0) { json = "{\"status\":\"提示信息\",\"message\":\"删除失败\"}"; } response.setContentType("text/html;charset=utf-8"); response.getWriter().write(json); } catch (IOException e) { e.printStackTrace(); } } /** * 修改用户信息 * @param request * @param response */ private void update(HttpServletRequest request, HttpServletResponse response) { int id = Integer.parseInt(request.getParameter("id")); TUserBean user = new TUserBean(); user = this.uDao.queryUserById(id); //获取前台传入的信息 String username = request.getParameter("username"); String password = request.getParameter("password"); String sex = request.getParameter("sex"); int age = Integer.parseInt(request.getParameter("age")); String birthday = request.getParameter("birthday"); int city = Integer.parseInt(request.getParameter("city")); String salary = request.getParameter("salary"); String starttime = request.getParameter("starttime"); String endtime = request.getParameter("endtime"); String description = request.getParameter("description"); //设置用户信息 user.setUsername(username); user.setPassword(password); user.setSex(sex); user.setAge(age); user.setBirthday(birthday); user.setCity(city); user.setSalary(salary); user.setStarttime(starttime); user.setEndtime(endtime); user.setDescription(description); try { //更新用户信息 int count = uDao.update(user); String json = "{\"status\":\"提示信息\",\"message\":\"更新成功\"}"; if(count != 1) { json = "{\"status\":\"提示信息\",\"message\":\"更新失败\"}"; } response.setContentType("text/html;charset=utf-8"); response.getWriter().write(json); } catch (IOException e) { e.printStackTrace(); } } /** * 保存用户信息 * @param request * @param response */ private void save(HttpServletRequest request, HttpServletResponse response) { //获取前台传入的信息 String username = request.getParameter("username"); String password = request.getParameter("password"); String sex = request.getParameter("sex"); int age = Integer.parseInt(request.getParameter("age")); String birthday = request.getParameter("birthday"); int city = Integer.parseInt(request.getParameter("city")); String salary = request.getParameter("salary"); String starttime = request.getParameter("starttime"); String endtime = request.getParameter("endtime"); String description = request.getParameter("description"); //设置用户信息 TUserBean user = new TUserBean(); user.setUsername(username); user.setPassword(password); user.setSex(sex); user.setAge(age); user.setBirthday(birthday); user.setCity(city); user.setSalary(salary); user.setStarttime(starttime); user.setEndtime(endtime); user.setDescription(description); try { //保存用户信息 int count = uDao.save(user); String json = "{\"status\":\"提示信息\",\"message\":\"保存成功\"}"; if(count != 1) { json = "{\"status\":\"提示信息\",\"message\":\"保存失败\"}"; } response.setContentType("text/html;charset=utf-8"); response.getWriter().write(json); } catch (IOException e) { e.printStackTrace(); } } /** * 获取全部城市信息 * @param request * @param response */ private void getCity(HttpServletRequest request, HttpServletResponse response) { try { List<CityBean> cList = new ArrayList<CityBean>(); cList.add(new CityBean(1,"北京")); cList.add(new CityBean(2,"上海")); cList.add(new CityBean(3,"深圳")); cList.add(new CityBean(4,"长春")); response.setContentType("text/html;charset=utf-8"); //[{"id":1,"name":"北京"},{"id":2,"name":"上海"},{"id":3,"name":"深圳"},{"id":4,"name":"长春"}] response.getWriter().write(JSONArray.fromObject(cList).toString()); } catch (IOException e) { e.printStackTrace(); } } /** * 获取城市信息 * @param request * @param response */ private void getCityName(HttpServletRequest request, HttpServletResponse response) { try { List<CityBean> cList = new ArrayList<CityBean>(); cList.add(new CityBean(1,"北京")); cList.add(new CityBean(2,"上海")); cList.add(new CityBean(3,"深圳")); cList.add(new CityBean(4,"长春")); int id = Integer.parseInt(request.getParameter("id")); for(CityBean city:cList) { if(id == city.getId()) { response.setContentType("text/html;charset=utf-8"); response.getWriter().write(JSONObject.fromObject(city).toString()); } } } catch (IOException e) { e.printStackTrace(); } } /** * 获取全部用户信息 * * @param request * @param response */ private void getList(HttpServletRequest request, HttpServletResponse response) { try { //当前页码 int currentPage = Integer.parseInt(request.getParameter("page")); //每页显示的大小 int pageSize = Integer.parseInt(request.getParameter("rows")); //前台查询条件 String username = request.getParameter("username") == null ? "" : request.getParameter("username"); String starttime = request.getParameter("starttime") == null ? "" : request.getParameter("starttime"); String endtime = request.getParameter("endtime") == null ? "" : request.getParameter("endtime"); TUserBean user = new TUserBean(); user.setUsername(username); user.setStarttime(starttime); user.setEndtime(endtime); // 获取分页显示的用户信息 List<TUserBean> uList = uDao.queryByPagination(currentPage, pageSize, user); //获取总用户数 int total = uDao.getTotal(user); // json格式 --> {"total":10,"rows":[{},{}]} String json = "{\"total\":" + total + ",\"rows\":" + JSONArray.fromObject(uList).toString() + "}"; response.setContentType("text/html;charset=utf-8"); response.getWriter().write(json); } catch (Exception e) { e.printStackTrace(); } } }
4、com.easyui.dao.UserDao.java
package com.easyui.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.easyui.bean.TUserBean; import com.easyui.util.DBUtil; /** * 用户数据库操作类 * @author LiPiaoShui */ public class UserDao { /** * 获取全部用户信息 * @return */ public List<TUserBean> getList() { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; List<TUserBean> uList = new ArrayList<TUserBean>(); try { String sql = "select * from t_user"; conn = DBUtil.getConnection(); pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery(); while(rs.next()) { TUserBean user = new TUserBean(); user.setId(rs.getInt("id")); user.setUsername(rs.getString("username")); user.setPassword(rs.getString("password")); user.setSex(rs.getString("sex")); user.setAge(rs.getInt("age")); user.setBirthday(rs.getString("birthday")); user.setCity(rs.getInt("city")); user.setSalary(rs.getString("salary")); user.setStarttime(rs.getString("starttime")); user.setEndtime(rs.getString("endtime")); user.setDescription(rs.getString("description")); uList.add(user); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, pstmt, conn); } return uList; } /** * 分页显示用户信息 * @param currentPage * @param pageSize * @return */ public List<TUserBean> queryByPagination(int currentPage,int pageSize, TUserBean userBean) { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; List<TUserBean> uList = new ArrayList<TUserBean>(); try { String sql = "select * from t_user where 1=1"; if(!"".equals(userBean.getUsername().trim())) { sql += " and username like '%" + userBean.getUsername() + "%'"; } if(!"".equals(userBean.getStarttime().trim())) { sql += " and starttime >= '" + userBean.getStarttime() + "'"; } if(!"".equals(userBean.getEndtime().trim())) { sql += " and endtime >= '" + userBean.getEndtime() + "'"; } sql += " limit ?,?"; conn = DBUtil.getConnection(); pstmt = conn.prepareStatement(sql); pstmt.setInt(1, (currentPage-1)*pageSize); pstmt.setInt(2, pageSize); rs = pstmt.executeQuery(); while(rs.next()) { TUserBean user = new TUserBean(); user.setId(rs.getInt("id")); user.setUsername(rs.getString("username")); user.setPassword(rs.getString("password")); user.setSex(rs.getString("sex")); user.setAge(rs.getInt("age")); user.setBirthday(rs.getString("birthday")); user.setCity(rs.getInt("city")); user.setSalary(rs.getString("salary")); user.setStarttime(rs.getString("starttime")); user.setEndtime(rs.getString("endtime")); user.setDescription(rs.getString("description")); uList.add(user); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, pstmt, conn); } return uList; } /** * 获取总用户数 * @return */ public int getTotal(TUserBean userBean) { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; int total = 0; try { String sql = "select count(1) from t_user where 1=1"; if(!"".equals(userBean.getUsername().trim())) { sql += " and username like '%" + userBean.getUsername() + "%'"; } if(!"".equals(userBean.getStarttime().trim())) { sql += " and starttime >= '" + userBean.getStarttime() + "'"; } if(!"".equals(userBean.getEndtime().trim())) { sql += " and endtime >= '" + userBean.getEndtime() + "'"; } conn = DBUtil.getConnection(); pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery(); if(rs.next()) { total = rs.getInt(1); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, pstmt, conn); } return total; } /** * 保存用户信息 * @param user * @return */ public int save(TUserBean user) { Connection conn = null; PreparedStatement pstmt = null; int count = 0; try { String sql = "insert into t_user(username,password,sex,age,birthday,city," + "salary,starttime,endtime,description) value(?,?,?,?,?,?,?,?,?,?)"; conn = DBUtil.getConnection(); pstmt = conn.prepareStatement(sql); pstmt.setString(1, user.getUsername()); pstmt.setString(2, user.getPassword()); pstmt.setString(3, user.getSex()); pstmt.setInt(4, user.getAge()); pstmt.setString(5, user.getBirthday()); pstmt.setInt(6, user.getCity()); pstmt.setString(7, user.getSalary()); pstmt.setString(8, user.getStarttime()); pstmt.setString(9, user.getEndtime()); pstmt.setString(10, user.getDescription()); count = pstmt.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(null, pstmt, conn); } return count; } /** * 根据用户ID查询用户信息 * @param id * @return */ public TUserBean queryUserById(int id) { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; TUserBean user = new TUserBean(); try { String sql = "select * from t_user where id=?"; conn = DBUtil.getConnection(); pstmt = conn.prepareStatement(sql); pstmt.setInt(1, id); rs = pstmt.executeQuery(); if(rs.next()) { user.setId(rs.getInt("id")); user.setUsername(rs.getString("username")); user.setPassword(rs.getString("password")); user.setSex(rs.getString("sex")); user.setAge(rs.getInt("age")); user.setBirthday(rs.getString("birthday")); user.setCity(rs.getInt("city")); user.setSalary(rs.getString("salary")); user.setStarttime(rs.getString("starttime")); user.setEndtime(rs.getString("endtime")); user.setDescription(rs.getString("description")); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, pstmt, conn); } return user; } /** * 更新用户信息 * @param user * @return */ public int update(TUserBean user) { Connection conn = null; PreparedStatement pstmt = null; int count = 0; try { String sql = "update t_user set username=?,password=?,sex=?,age=?,birthday=?,city=?," + "salary=?,starttime=?,endtime=?,description=? where id=?"; conn = DBUtil.getConnection(); pstmt = conn.prepareStatement(sql); pstmt.setString(1, user.getUsername()); pstmt.setString(2, user.getPassword()); pstmt.setString(3, user.getSex()); pstmt.setInt(4, user.getAge()); pstmt.setString(5, user.getBirthday()); pstmt.setInt(6, user.getCity()); pstmt.setString(7, user.getSalary()); pstmt.setString(8, user.getStarttime()); pstmt.setString(9, user.getEndtime()); pstmt.setString(10, user.getDescription()); pstmt.setInt(11, user.getId()); count = pstmt.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(null, pstmt, conn); } return count; } /** * 根据用户ID删除用户信息 * @param id * @return */ public int deleteByUserId(int id) { Connection conn = null; PreparedStatement pstmt = null; int count = 0; try { String sql = "delete from t_user where id=?"; conn = DBUtil.getConnection(); pstmt = conn.prepareStatement(sql); pstmt.setInt(1, id); count = pstmt.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(null, pstmt, conn); } return count; } /** * 根据名字查询用户信息 * @return */ public List<TUserBean> searchByName(String q) { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; List<TUserBean> uList = new ArrayList<TUserBean>(); try { String sql = "select * from t_user where 1=1"; if(!"".equals(q)) { sql += " and username like '%" + q + "%'"; } conn = DBUtil.getConnection(); pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery(); while(rs.next()) { TUserBean user = new TUserBean(); user.setId(rs.getInt("id")); user.setUsername(rs.getString("username")); user.setPassword(rs.getString("password")); user.setSex(rs.getString("sex")); user.setAge(rs.getInt("age")); user.setBirthday(rs.getString("birthday")); user.setCity(rs.getInt("city")); user.setSalary(rs.getString("salary")); user.setStarttime(rs.getString("starttime")); user.setEndtime(rs.getString("endtime")); user.setDescription(rs.getString("description")); uList.add(user); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, pstmt, conn); } return uList; } }
相关推荐
在这个特定的案例中,我们关注的是“易语言选择当天时间组件 - 组合框拼接源码”。这个标题表明我们将探讨如何在易语言中利用组件来获取当前日期,并将其与组合框(ComboBox)中的数据进行拼接操作。 组合框,也...
#### 二、Extjs4 combobox组件介绍 1. **基础概念**: - `combobox`(组合框)是Extjs框架中一种常用的UI控件,用于展示下拉列表供用户选择。 - 在本例中,combobox被用来实现省市区的选择功能,即用户选择省份后...
在这个案例中,UIComboBox可能是基于UITextField扩展的,增加了一个可展开/收起的列表视图,用于显示可供选择的选项。 3. **Objective-C或Swift实现** "IOS-UIComboBox"可能使用Objective-C或Swift编写。Objective...
标题中的“jQuery ComboBox”指的是一个基于jQuery库的下拉选择框组件。这个组件通常用于创建具有下拉选项的输入控件,它结合了输入框和下拉列表的功能,提供了更丰富的用户交互体验。在网页开发中,jQuery ComboBox...
在这个案例中,“选择当天时间组件”可能是一个自定义的组件,用于获取和展示系统当前的日期和时间。 组合框(Combobox)是易语言中一种常见的控件,它可以同时具备下拉列表和输入框的功能。在本例中,组合框可能是...
Ext 2.0的Combobox组件主要包含以下几个关键属性和方法: 1. **store**:这是Combobox的数据源,通常是一个Ext.data.Store对象,用于存储省份和城市的数据。数据可以是XML、JSON或其他格式,通过配置reader进行解析...
16.强大的DataGrid组件[8]_内嵌ComboBox动态数据联动 17.强大的DataGrid组件[9]_自定义头模板(HeaderTemplate) 18.强大的DataGrid组件[10]_自定义脚模板(FooterTemplate) 19.强大的DataGrid组件[11]_主从(Master-...
本案例中的"自定义多列模糊搜索的devCombox"就是一个针对dev控件的增强,它扩展了标准ComboBox的功能,提供了更丰富的用户体验和更灵活的数据检索方式。 首先,"devCombox"这个名字表明它是基于dev(可能指的是...
在程序设计领域,自动查询技术(Auto Query Technique)被广泛应用于多种场景中,尤其是对于用户界面(UI)组件如组合框(ComboBox)。该技术的主要目的是提高用户体验,通过允许用户在输入文本时能够立即从列表中获得...
本篇将详细阐述如何利用Ext JS框架中的ComboBox组件实现类似百度搜索的自动提示功能,包括其配置参数、工作原理以及实际应用。 ### 一、Ext ComboBox概述 Ext JS是一个用JavaScript编写的开源前端框架,用于构建...
在C#编程中,ComboBox控件是一种常用的选择组件,常用于实现用户界面中的选择交互。在三层架构(Presentation Layer, Business Logic Layer, Data Access Layer)中,ComboBox的联动操作意味着当用户在一个ComboBox...
此外,ExtJS还提供了一系列示例(examples),通过实际案例演示如何运用各种组件和功能,帮助开发者快速上手。 #### 资源与国际化(resources & locale) 资源目录(resources)存放了ExtJS的用户界面资源,包括...
同时,补全列表的显示和选择也需要相应的UI组件支持,如ComboBox或ListView。 4. **异步编程**:为了保持界面的响应性,服务器响应的获取通常会用到异步编程。C#的async/await关键字可以帮助我们编写非阻塞的代码,...
例如,使用`List`组件显示所有书籍,`TextField`和`Button`组合实现搜索功能,`ComboBox`用于分类筛选。 7. 文件I/O操作: 图书信息通常存储在文件或数据库中。JAVA的`java.io`包提供了读写文件的类和方法,如`...
这个标签暗示我们可能正在处理一个与`Combobox`组件相关的解决方案,而这个组件可能已经内置了对自定义高度的支持。 资源文件通常包含实现特定功能所需的各种代码片段、样式表(CSS)、图片或者其他辅助资源。在这...
- **配置与设置**:可以通过“工具”菜单中的“选项”来配置 IDE 的行为,如自动完成、缩进等。 #### 三、基础语法与概念 - **变量声明与类型**:VB 6.0 支持多种数据类型,如 Integer、String、Boolean 等。使用 ...
它提供了丰富的功能,如自动完成、多选、搜索过滤等,适用于构建交互式Web界面。DHTMLX Combo易于集成,支持各种浏览器,并且提供了灵活的API供开发者自定义行为和样式。 2. **DHTMLTreeGrid**: 虽然标题中提到...
在ExtJS中,为了实现一个具有下拉树结构的ComboBox,即ComboBoxTree,通常需要自定义组件,因为原生的ExtJS库并不直接提供这样的功能。以下是对标题和描述中所述知识点的详细解释: 1. **自定义组件**: 在ExtJS中...
- 可能是指用户界面的一部分,也可能指应用程序的某个组件。 2. **Command**: - 命令对象,用于执行SQL命令或存储过程。 - `IntegratedSecurity=true`:表示使用集成安全性连接数据库,即使用当前用户的Windows...