zoukankan      html  css  js  c++  java
  • 使用Dapper参数化查询(二)

    查询封装

    /// <summary>
        /// 分页查询条件
        /// </summary>
        public class PageWhere
        {
            /// <summary>
            /// 
            /// </summary>
            public QueryWhere queryWhere { get; set; }
            /// <summary>
            /// 每页显示数量
            /// </summary>
            public int pageSize { get; set; }
            /// <summary>
            /// 第几页
            /// </summary>
            public int pageIndex { get; set; }
            /// <summary>
            /// 排序字段
            /// </summary>
            public string filedOrder { get; set; }
        }
    
        /// <summary>
        /// 查询条件
        /// </summary>
        public class QueryWhere
        {
            public QueryWhere()
            {
                listWhere = new List<string>();
                dicWhere = new List<DicWhere>();
            }
            /// <summary>
            /// 查询条件
            /// </summary>
            public List<string> listWhere { get; set; }
            /// <summary>
            /// 赋值
            /// </summary>
            public List<DicWhere> dicWhere { get; set; }
        }
    
        /// <summary>
        /// 字段==值
        /// </summary>
        public class DicWhere
        {
            /// <summary>
            /// 字段
            /// </summary>
            public string filed { get; set; }
            /// <summary>
            /// 对应值
            /// </summary>
            public object value { get; set; }
        }

    转换为dapper的dy

    QueryParameter qp = new QueryParameter();
    qp.listWhere = pageWhere.queryWhere.listWhere;
    pageWhere.queryWhere.dicWhere.ForEach(item =>
    {
       qp.dynamicParameter.Add(item.filed, item.value);
    });
    return _prerecordBLL.GetList(qp, pageWhere.pageSize, pageWhere.pageIndex, pageWhere.filedOrder);

    调用

    if (!string.IsNullOrWhiteSpace(gltxtcinput.Text))
    {
       qw.listWhere.Add(" a.cinput=@cinput ");
       qw.dicWhere.Add(new DicWhere() { filed = "@cinput", value = gltxtcinput.EditValue });
    }
  • 相关阅读:
    springboot + swagger的实体类属性注解
    Idea破解办法+idea免费生成注册码+jsp属性选择器+注解什么的都报错
    springboot笔记(一)
    docker-compose 安装
    Spring cloud 分布式锁
    Mybait 快速生成Java POJO文件 及数据库Mapping文件。
    Git 提交所有文件
    Docker dockerfile-maven-plugin 使用
    Docker remote api 开启
    Linux git 关联 github仓库
  • 原文地址:https://www.cnblogs.com/shuaimeng/p/13962616.html
Copyright © 2011-2022 走看看