java 分页查询_JavaWeb之分页查询

时间:2016-12-11 01:41

1、分页的优点:

只查询一页,不需要查询所有数据,能够提高效率。

2、分页数据

页面的数据都是由Servlet传递的

*   当前页:pageCode

>   如果页面没有向Servlet传递页码,那么Servlet默认为第一页,否则按照传递页码为准。

*   总页数:totalPages

>   总记录数 / 每页记录数

*   总记录数:totalRecord

>   Dao来获取,select count(*) from customer

*   每页记录数:称为业务数据或系统数据。

*   当前页数据:beanList

*   URL

3、数据的传递

这些分页数据总要在各层之间来回传递,可以把这些分页数据封装到一个JavaBean中,它就叫分页Bean,例如:PageBean。

import java.util.List;

public class PageBean {

// 当前页码pageCode

private int pageCode;

/*

* 总页数

* 通过计算得出,不允许外界设置值

* 因为只能get,所以不需要成员变量,通过计算即可得出

*/

// private int totalPages;

// 总记录数

private int totalRecord;

// 每页记录数

private int pageSize;

// 当前页的记录

private List beanList;

public int getPageCode() {

return pageCode;

}

public void setPageCode(int pageCode) {

this.pageCode = pageCode;

}

public int getTotalPages() {

/*

* 计算总页数

* 通过总记录数和每页记录数来计算总页数,当存在余数时,总页数 + 1

*/

int totalPages = totalRecord / pageSize;

return totalRecord % pageSize == 0 ? totalPages : totalPages + 1;

}

// public void setTotalPages(int totalPages) {

// this.totalPages = totalPages;

// }

public int getTotalRecord() {

return totalRecord;

}

public void setTotalRecord(int totalRecord) {

this.totalRecord = totalRecord;

}

public int getPageSize() {

return pageSize;

}

public void setPageSize(int pageSize) {

this.pageSize = pageSize;

}

public List getBeanList() {

return beanList;

}

public void setBeanList(List beanList) {

this.beanList = beanList;

}

@Override

public String toString() {

return "PageBean [pageCode=" + pageCode + ", totalPages=" + ", totalRecord=" + totalRecord + ", pageSize=" + pageSize + ", beanList=" + beanList + "]";

}

public PageBean(int pageCode, int totalRecord, int pageSize, List beanList) {

super();

this.pageCode = pageCode;

this.totalRecord = totalRecord;

this.pageSize = pageSize;

this.beanList = beanList;

}

public PageBean() {

super();

}

}

4、分页在各层中的处理

*   页面:给出分页相关的链接。

>   页面需要给Servlet传递当前页码。

*   Servlet:创建PageBean对象, 给PageBean对象所有的属性赋值,然后传递给页面。

>   给Dao传递当前页码和每页记录数。

*   Service:略

*   Dao

>   负责获取:totalRecord,select count(*) from customer

>   负责获取:BeanList,select * from customer limit x, y,从x行开始,查询y行。

>   limit计算公式:(当前页-1) * 每页记录数,得出的就是起始行

b67fd7d32c83fa6103be5b1319452cbf.png

5、显示分页页码列表

1 2 3 4 5 6 7 8 9 10

*   最多显示多少个页码?

>   暂定10个

*   当前页在页码列表中的位置?

>   暂定为6

只需要pageCode就可以完成页码列表,需要使用pageCode来推算出起始页码(begin)和结束页码(end)

计算公式:

*   如果总页数 <= 10(列表长度),那么begin = 1,end = 总页数

*   如果总页数 > 10,使用公式计算

>   begin = pageCode - 5

>   end = pageCode + 4

>   begin溢出:当begin小于1时,让begin = 1

>   end溢出:当end > totalPages时,让end = totalPages

6、在超链接中保留请求参数

当使用多条件查询时,如果点击其它超链接,会丢失原超链接中的参数,也就是丢失请求条件,所以需要在页面的所有超链接中都要保留参数。

可以把?后的全部参数用一个字符串保存到PageBean的URL属性中,这个任务交给Servlet。

然后在页面中使用${pageBean.url }来设置超链接。

——项目代码

114d4921a825d3d568c80e7b0d42ff4f.png

===============================================================================

com.wyc.cstm.dao.CustomerDao

import java.util.ArrayList;

import java.util.List;

import org.apache.commons.dbutils.QueryRunner;

import org.apache.commons.dbutils.handlers.BeanListHandler;

import org.apache.commons.dbutils.handlers.ScalarHandler;

import com.wyc.cstm.domain.Customer;

import com.wyc.cstm.domain.PageBean;

import com.wyc.jdbc.TxQueryRunner;

/**

* 持久层 通过QueryRunner来操作数据库

*

* @author 31067

*

*/

public class CustomerDao {

private QueryRunner qr = new TxQueryRunner();

// /*

// * 查询全部客户信息

// */

// public List findAll() {

// try {

// String sql = "select * from customer";

// return qr.query(sql, new BeanListHandler(Customer.class));

// } catch (Exception e) {

// throw new RuntimeException(e);

// }

// }

public PageBean findAll(int pageCode, int pageSize) {

try {

/*

* 1、创建PageBean对象 2、设置PageBean对象的pageCode和pageSize

* 3、得到totalRecord,设置给pageBean 4、得到beanList,设置给pageBean 5、返回pageBean

*/

PageBean pageBean = new PageBean();

/*

* 设置pageCode、pageSize

*/

pageBean.setPageCode(pageCode);

pageBean.setPageSize(pageSize);

/*

* 得到totalRecord

*/

String sql = "select count(*) from customer";

// 返回值类型是Object,强转为Number类型

Number num = (Number) qr.query(sql, new ScalarHandler());

int totalRecord = num.intValue();

pageBean.setTotalRecord(totalRecord);

/*

* 得到beanList

*/

sql = "select * from customer order by cname limit ?, ?";

// (当前页码 - 1) * 每行记录数 = 起始行

Object[] params = { (pageCode - 1) * pageSize, pageSize };

List beanList = qr.query(sql, new BeanListHandler(Customer.class), params);

pageBean.setBeanList(beanList);

return pageBean;

} catch (Exception e) {

throw new RuntimeException(e);

}

}

/**

* 多条件组合查询

*

* @param criteria

* @return

*/

// public List query(Customer criteria) {

// /*

// * 1、给出SQL模板

// * 2、给出参数

// * 3、调用query()方法

// * 结果集处理器:BeanListHandler

// */

//

// // 给出SQL语句的前半部分

// StringBuilder sql = new

// StringBuilder("select * from customer where 1 = 1");

// /*

// * 1、判断条件,向SQL语句中追加where子句

// * 因为不能确定是否包含该参数,所以需要使用if语句来判断

// * 2、给出参数

// * 因为不能确定?占位符所对应的参数,所以在判断参数时,就要添加参数

// * 使用ArrayList来装载参数

// */

//

// // 装载参数

// List params = new ArrayList();

//

//

// String cname = criteria.getCname();

// if(cname != null && !cname.trim().isEmpty())

// {

// sql.append(" and cname = ?");

// //模糊查询

// params.add("%" + cname + "%");

// }

//

// String gender = criteria.getGender();

// if(gender != null && !gender.trim().isEmpty())

// {

// sql.append(" and gender = ?");

// params.add(gender);

// }

//

// String cellphone = criteria.getCellphone();

// if(cellphone != null && !cellphone.trim().isEmpty())

// {

// sql.append(" and cellphone = ?");

// params.add("%" + cellphone + "%");

// }

//

// String email = criteria.getEmail();

// if(email != null && !email.trim().isEmpty())

// {

// sql.append(" and email = ?");

// params.add("%" + email + "%");

// }

//

// /*

// * 执行query

// */

// try {

// return qr.query(sql.toString(), new

// BeanListHandler(Customer.class), params.toArray());

// } catch (SQLException e) {

// throw new RuntimeException(e);

// }

// }

public PageBean query(Customer criteria, int pageCode, int pageSize) {

try {

/*

* 1、创建PageBean对象 2、设置已有属性,pageCode和pageSize 3、得到totalRecord

* 4、得到BeanList

*/

/*

* 创建PageBean对象,设置已有属性

*/

PageBean pageBean = new PageBean();

pageBean.setPageCode(pageCode);

pageBean.setPageSize(pageSize);

/*

* 得到tr,需要根据条件进行查询

*/

// 给出SQL语句的前半部分

StringBuilder countSql = new StringBuilder("select count(*) from customer");

StringBuilder whereSql = new StringBuilder(" where 1 = 1");

/*

* 1、判断条件,向SQL语句中追加where子句 因为不能确定是否包含该参数,所以需要使用if语句来判断 2、给出参数

* 因为不能确定?占位符所对应的参数,所以在判断参数时,就要添加参数 使用ArrayList来装载参数

*/

// 装载参数

List params = new ArrayList();

String cname = criteria.getCname();

if (cname != null && !cname.trim().isEmpty()) {

whereSql.append(" and cname like ?");

// 模糊查询

params.add("%" + cname + "%");

}

String gender = criteria.getGender();

if (gender != null && !gender.trim().isEmpty()) {

whereSql.append(" and gender = ?");

params.add(gender);

}

String cellphone = criteria.getCellphone();

if (cellphone != null && !cellphone.trim().isEmpty()) {

whereSql.append(" and cellphone like ?");

params.add("%" + cellphone + "%");

}

String email = criteria.getEmail();

if (email != null && !email.trim().isEmpty()) {

whereSql.append(" and email like ?");

params.add("%" + email + "%");

}

/*

* 执行SQL语句 select count(*) from customer = where ....

*/

Number num = (Number) qr.query(countSql.append(whereSql).toString(), new ScalarHandler(), params.toArray());

int totalRecord = num.intValue();

pageBean.setTotalRecord(totalRecord);

/*

* 得到beanList

*/

StringBuilder sql = new StringBuilder("select * from customer");

/*

* 查询beanList这一步还需要给出limit子句

*/

StringBuilder limitSql = new StringBuilder(" limit ?,?");

/*

* params中需要给出limit后对应的参数值

*/

params.add((pageCode - 1) * pageSize);

params.add(pageSize);

List beanList = qr.query(sql.append(whereSql).append(limitSql).toString(), new BeanListHandler(Customer.class), params.toArray());

pageBean.setBeanList(beanList);

return pageBean;

} catch (Exception e) {

throw new RuntimeException(e);

}

}

}

===============================================================================

com.wyc.cstm.domain.Customer

/**

* 领域对象

* 与表单和数据库表对应

*/

public class Customer {

/*

* 对应数据库表:

* cid CHAR(32) PRIMARY KEY,

* cname VARCHAR(40) NOT NULL,

* gender VARCHAR(6) NOT NULL,

* birthday CHAR(10),

* cellphone VARCHAR(15),

* email VARCHAR(40),

* description VARCHAR(500)

*/

private String cid;//主键

private String cname;//客户姓名

private String gender;//性别

private String birthday;//客户生日

private String cellphone;//客户手机

private String email;//客户邮箱

private String description;//客户信息描述

public String getCid() {

return cid;

}

public void setCid(String cid) {

this.cid = cid;

}

public String getCname() {

return cname;

}

public void setCname(String cname) {

this.cname = cname;

}

public String getGender() {

return gender;

}

public void setGender(String gender) {

this.gender = gender;

}

public String getBirthday() {

return birthday;

}

public void setBirthday(String birthday) {

this.birthday = birthday;

}

public String getCellphone() {

return cellphone;

}

public void setCellphone(String cellphone) {

this.cellphone = cellphone;

}

public String getEmail() {

return email;

}

public void setEmail(String email) {

this.email = email;

}

public String getDescription() {

return description;

}

public void setDescription(String description) {

this.description = description;

}

@Override

public String toString() {

return "Customer [cid=" + cid + ", cname=" + cname + ", gender=" + gender + ", birthday=" + birthday + ", cellphone=" + cellphone + ", email=" + email + ", description=" + description + "]";

}

public Customer(String cid, String cname, String gender, String birthday, String cellphone, String email, String description) {

super();

this.cid = cid;

this.cname = cname;

this.gender = gender;

this.birthday = birthday;

this.cellphone = cellphone;

this.email = email;

this.description = description;

}

public Customer() {

super();

}

}

===============================================================================

com.wyc.cstm.service.CustomerService

import com.wyc.cstm.dao.CustomerDao;

import com.wyc.cstm.domain.Customer;

import com.wyc.cstm.domain.PageBean;

/**

* 业务层 依赖Dao

*/

public class CustomerService {

private CustomerDao customerDao = new CustomerDao();

// /**

// * 查询所有客户

// * @return

// */

// public List findAll(){

// return customerDao.findAll();

// }

public PageBean findAll(int pageCode, int pageSize) {

return customerDao.findAll(pageCode, pageSize);

}

/**

* 多条件组合查询

*

* @param criteria

* @return

*/

public PageBean query(Customer criteria, int pageCode, int pageSize) {

return customerDao.query(criteria, pageCode, pageSize);

}

}

===============================================================================

com.wyc.cstm.web.servlet.CustomerServlet

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import com.wyc.bean.CommonUtils;

import com.wyc.cstm.domain.Customer;

import com.wyc.cstm.domain.PageBean;

import com.wyc.cstm.service.CustomerService;

import com.wyc.servlet.BaseServlet;

/**

* Web层

*

* @author 31067

*

*/

public class CustomerServlet extends BaseServlet {

private CustomerService customerService = new CustomerService();

// public String findAll(HttpServletRequest request, HttpServletResponse

// response) throws ServletException, IOException {

// /*

// * 1、调用service得到所有客户

// * 2、将全部信息保存到request域中

// * 3、转发到list.jsp

// */

// request.setAttribute("cstmList", customerService.findAll());

// return "f:/list.jsp";

// }

public String findAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

/*

* 1、获取页面传递的pageCode

* 2、给定pageSize的值

* 3、使用pageCode和pageSize调用Service方法,得到PageBean对象

* 4、将PageBean对象保存到request域中

* 5、转发到list.jsp

*/

/*

* 1、得到pageCode有两种可能

*     如果pageCode参数不存在,说明pageCode = 1

*     如果pageCode参数存在,只需要将参数转换成int类型即可

*/

int pageCode = getPageCode(request);

/*

* 2、给定pageSize的值,每页10行

*/

int pageSize = 10;

/*

* 3、调用Service的findAll方法

*     传递pageCode和pageSize给Service方法

*     返回PageBean对象

*/

PageBean pageBean = customerService.findAll(pageCode, pageSize);

/*

* 添加URL及参数

*/

pageBean.setUrl(getUrl(request));

/*

* 4、将PageBean对象保存到request域中

*/

request.setAttribute("pageBean", pageBean);

return "f:list.jsp";

}

private int getPageCode(HttpServletRequest request) {

String value = request.getParameter("pageCode");

if (value == null || value.trim().isEmpty()) {

return 1;

}

return Integer.parseInt(value);

}

// public String query(HttpServletRequest request, HttpServletResponse

// response) throws ServletException, IOException {

// /*

// * 1、封装表单数据到Customer对象中,它只有四个属性:cname、gender、cellphone、email

// * 它其实就是一个查询条件的组合对象

// * 2、调用Service的query()方法,得到List

// * 3、将List保存到request域中

// * 4、转发到list.jsp

// */

//

// Customer criteria = CommonUtils.toBean(request.getParameterMap(),

// Customer.class);

// List cstmList = customerService.query(criteria);

// request.setAttribute("cstmList", cstmList);

// return "f:list.jsp";

// }

public String query(HttpServletRequest request, HttpServletResponse response) throws Exception {

/*

* 0、把条件参数封装到Customer对象中 1、获取页面传递的pageCode 2、给定pageSize的值

* 3、使用pageCode和pageSize以及条件字符串调用Service方法,得到PageBean对象

* 4、将PageBean对象保存到request域中 5、转发到list.jsp

*/

// 获取查询条件

Customer criteria = CommonUtils.toBean(request.getParameterMap(), Customer.class);

/*

* 处理GET请求方式编码问题

*/

criteria = encoding(criteria);

int pageCode = getPageCode(request);

int pageSize = 10;

PageBean pageBean = customerService.query(criteria, pageCode, pageSize);

/*

* 得到URL,保存到pageBean中

*/

pageBean.setUrl(getUrl(request));

request.setAttribute("pageBean", pageBean);

return "f:list.jsp";

}

/**

* 处理数据的编码问题

*

* @throws Exception

*/

private Customer encoding(Customer criteria) throws Exception {

String cname = criteria.getCname();

String gender = criteria.getGender();

String cellphone = criteria.getCellphone();

String email = criteria.getEmail();

if (cname != null && !cname.trim().isEmpty()) {

cname = new String(cname.getBytes("iso-8859-1"), "utf-8");

criteria.setCname(cname);

}

if (gender != null && !gender.trim().isEmpty()) {

gender = new String(gender.getBytes("iso-8859-1"), "utf-8");

criteria.setGender(gender);

}

if (cellphone != null && !cellphone.trim().isEmpty()) {

cellphone = new String(cellphone.getBytes("iso-8859-1"), "utf-8");

criteria.setCellphone(cellphone);

}

if (email != null && !email.trim().isEmpty()) {

email = new String(email.getBytes("iso-8859-1"), "utf-8");

criteria.setEmail(email);

}

return criteria;

}

/**

* 截取请求URL /项目名/Servlet路径?参数字符串

*

* @param request

* @return

*/

private String getUrl(HttpServletRequest request) {

// 获取项目名

String contextPath = request.getContextPath();

// 获取ServletPath,即/CustomerServlet

String servletPath = request.getServletPath();

// 获取问号之后的参数部分

String queryString = request.getQueryString();

/*

* 判断queryString中是否包含pageCode 如果包含,需要截取掉pageCode

*/

if (queryString.contains("&pageCode=")) {

int index = queryString.lastIndexOf("&pageCode=");

queryString = queryString.substring(0, index);

}

return contextPath + servletPath + "?" + queryString;

}

}

===============================================================================

c3p0-config.xml

jdbc:mysql://localhost:3306/customers

com.mysql.jdbc.Driver

root

Admin123

3

10

2

10

===============================================================================

frame.jsp

String path = request.getContextPath();

String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

%>

主页

===============================================================================

list.jsp

String path = request.getContextPath();

String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

%>

My JSP 'list.jsp' starting page
姓名性别生日手机号码邮箱描述

要遍历的是pageBean对象的beanList集合

--%>

${cstm.cname }${cstm.gender }${cstm.birthday }${cstm.cellphone }${cstm.email }${cstm.description }

编辑

删除

给出分页相关的链接

--%>

进行设置了 --%>

首页

上一页

= 10 --%>

[${i }]

${i }

下一页

尾页

第${pageBean.pageCode }页/共${pageBean.totalPages }页

===============================================================================

query.jsp

String path = request.getContextPath();

String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

%>

My JSP 'query.jsp' starting page

高级搜索

客户名称
客户性别

请选择

手机
邮箱
 

===============================================================================

top.jsp

String path = request.getContextPath();

String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

%>

My JSP 'top.jsp' starting page

客户关系管理系统

添加客户  |

查询客户 |

高级搜索 |

返回首页

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/438597.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

第三节:深度剖析各类数据结构(Array、List、Queue、Stack)及线程安全问题和yeild关键字

一. 各类数据结构比较及其线程安全问题 1. Array(数组)&#xff1a; 分配在连续内存中,不能随意扩展&#xff0c;数组中数值类型必须是一致的。数组的声明有两种形式&#xff1a;直接定义长度&#xff0c;然后赋值&#xff1b;直接赋值。 缺点&#xff1a;插入数据慢。 优点&a…

第四节:IO、序列化和反序列化、加密解密技术

一. IO读写   这里主要包括文件的读、写、移动、复制、删除、文件夹的创建、文件夹的删除等常规操作。 注意&#xff1a;这里需要特别注意&#xff0c;对于普通的控制台程序和Web程序&#xff0c;将"相对路径"转换成"绝对路径"的方法不一致。 (1). 在w…

java mediator_java—mediator中介模式

中介者模式是由GoF提出的23种软件设计模式的一种。Mediator模式是行为模式之一&#xff0c;Mediator模式定义:用一个中介者对象来封装一系列的对象交互。中介者使各对象不需要显式的相互引用&#xff0c;从而使其耦合松散&#xff0c;而且可以独立的改变他们之间的交互。适用性…

第五节:泛型(泛型类、接口、方法、委托、泛型约束、泛型缓存、逆变和协变)

一. 泛型诞生的背景 在介绍背景之前&#xff0c;先来看一个案例&#xff0c;要求&#xff1a;分别输出实体model1、model2、model3的id和name值,这三个实体有相同的属性名字id和name。 1 public class myUtils2 {3 //要求&#xff1a;分别输出实体model1、model2、…

第六节:反射(几种写法、好处和弊端、利用反射实现IOC)

一. 加载dll,读取相关信息 1. 加载程序集的三种方式 调用Assembly类下的三个方法&#xff1a;Load、LoadFile、LoadFrom。 1       //1.1 Load方法&#xff1a;动态默认加载当前路径下的(bin)下的dll文件,不需要后缀 2 Assembly assembly Assembly.Load(&…

第七节:语法总结(1)(自动属性、out参数、对象初始化器、var和dynamic等)

一. 语法糖简介 语法糖也译为糖衣语法&#xff0c;是由英国计算机科学家彼得约翰兰达&#xff08;Peter J. Landin&#xff09;发明的一个术语&#xff0c;指计算机语言中添加的某种语法&#xff0c;这种语法对语言的功能并没有影响&#xff0c;但是更方便程序员使用。通常来说…

java不用插件播放媒体文件_java servlet不用插件上传文件:

展开全部import java.net.*;import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;public class SaveFileServlet extends HttpServlet{FileWriter savefile;String filename null;String value null;/*** Handles a POST request*/publ…

第八节:语法总结(2)(匿名类、匿名方法、扩展方法)

一. 匿名类 1. 传统的方式给类赋值&#xff0c;需要先建一个实体类→实例化→赋值&#xff0c;步骤很繁琐&#xff0c;在.Net 3.0时代&#xff0c;微软引入匿名类的概念&#xff0c;简化了代码编写&#xff0c;提高了开发效率。 匿名类的声明语法&#xff1a; var objnew {字段…

第九节:委托和事件(1)(委托的发展历史、插件式编程、多播委托)

一. 委托的发展历史和基本用法 说起委托&#xff0c;每个人可能都会对他有不同的理解&#xff0c;结合实战中委托的使用&#xff0c;我对其理解是&#xff1a;委托和类一样&#xff0c;是用户的一个自定义类型&#xff0c;委托可以有参数、有返回值&#xff0c;委托的关键字是d…

第十节:委托和事件(2)(泛型委托、Func和Action、事件及与委托的比较)

一. 泛型委托 所谓的泛型委托&#xff0c;即自定义委托的参数可以用泛型约束&#xff0c;同时内置委托Func和Action本身就是泛型委托。 将上一个章节中的Calculator类中的方法用自定义泛型委托重新实现一下。 1 public class Calculator22 {3 //传统解决方案一&am…

java+sm4+加密算法_SM4加密算法实现Java和C#相互加密解密

https://www.cnblogs.com/miaoziblog/p/9040473.html近期由于项目需要使用SM4对数据进行加密&#xff0c;然后传给Java后台&#xff0c;Java后台使用的也是SM4的加密算法但是就是解密不正确&#xff0c;经过一步步调试发现Java中好多数据类型与C#的相同的数据类型是存在不同的比…

DotNet进阶系列

一. 回顾历史 回顾个人发展历程&#xff0c;自2012年初次接触开发至今(2018年)已经有六个年头&#xff0c;这期间陆陆续续学习并掌握了不少技术&#xff0c;C#语言、ORM框架、多线程技术、设计模式、前端技术、MVC、MVVM框架思想等等&#xff0c;每种技术随着多次使用&#xff…

第十一节:特性(常见的特性标签、自定义特性、特性的使用案例)

一. 基本概念 1. 什么是特性? MSDN官方给出的定义时&#xff1a;公共语言运行时允许添加类似关键字的描述声明&#xff0c;叫做特性&#xff0c;它对程序中的元素进行标注&#xff0c;如类型、字段、方法和属性等。Attribute和Microsoft .Net Framework文件的元数据&#xff…

第十二节:Lambda、linq、SQL的相爱相杀(1)

一. 谈情怀 Lambda、Linq、SQL伴随着我的开发一年又一年&#xff0c;但它们三者并没有此消彼长&#xff0c;各自占有这一定的比重&#xff0c;起着不可替代的作用。 相信我们最先接触的应该就是SQL了&#xff0c;凡是科班出身的人&#xff0c;大学期间都会学习SQL Server数据库…

php java 共享session_PHP 实现多服务器共享 SESSION 数据

一、问题起源稍大一些的网站&#xff0c;通常都会有好几个服务器&#xff0c;每个服务器运行着不同功能的模块&#xff0c;使用不同的二级域名&#xff0c;而一个整体性强的网站&#xff0c;用户系统是统一的&#xff0c;即一套用户名、密码在整个网站的各个模块中都是可以登录…

第十三节:Lambda、linq、SQL的相爱相杀(2)

一. Linq开篇 1.Where用法 linq中where的用法与SQL中where的用法基本一致。 1 #region 01-where用法2 {3 //1. where用法4 //1.1 查询账号为admin的用户信息5 Console.WriteLine("------------…

第十四节:Lambda、linq、SQL的相爱相杀(3)

一. SQL 开篇 1. where用法 1    #region 封装EF调用SQL语句查询 2 public static List<T> ExecuteQuery<T>(string sql, params SqlParameter[] pars) 3 { 4 return db.Database.SqlQuery<T>(sql, pars).ToList(); 5 …

第十五节:Expression表达式目录树(与委托的区别、自行拼接、总结几类实例间的拷贝)

一. 基本介绍 回忆&#xff1a; 最早接触到表达式目录树(Expression)可能要追溯到几年前使用EF早期的时候&#xff0c;发现where方法里的参数是Expression<Func<T,bool>>这么一个类型&#xff0c;当初不是很理解&#xff0c;只是知道传入lambda表达式使用即可&…

IIS Web 服务器/ASP.NET 运行原理基本知识概念整理

前言&#xff1a; 记录 IIS 相关的笔记还是从公司笔试考核题开始的&#xff0c;问 Application Pool 与 AppDomain 的区别&#xff1f; 促使我对进程池进了知识的学习&#xff0c;所以记录一下学习的笔记。 我们知道现在 .NET 就业来看&#xff0c;80% 的 .NET 程序员都是从事 …

Http请求处理流程

从一个页面比如www.xuxiaoyu.net的请求开始如何就能打开blogs页面的呢&#xff1f;这其中发生了什么样的东西&#xff1f; Http请求(Http Request) 当服务器&#xff08;IIS&#xff09;接受到一个Http请求的时候进行以下步骤的处理&#xff1a; 1)服务器获取所请求的页面的后缀…