闲来无事做了一个项目,内有redis,EasyUI样式简单应用,七层分页查询,API跨域。
<link href="~/jquery-easyui-1.5.3/themes/default/easyui.css" rel="stylesheet" />
<link href="~/jquery-easyui-1.5.3/themes/icon.css" rel="stylesheet" />
<script src="~/jquery-easyui-1.5.3/jquery-1.7.1.min.js"></script>
<script src="~/jquery-easyui-1.5.3/jquery.easyui.min.js"></script>
<script src="~/jquery-easyui-1.5.3/locale/easyui-lang-zh_CN.js"></script>
以上是样式的jquery引用 想要用的可以用EasyUI官网,本人菜的很,不太会用,有大神求提点一下。(哎,有点笨,嘿嘿)
<div style="" data-options="region:'center'">
<div class="easyui-tabs" data-options="fit:true">
<div data-options="iconCls:'icon-save', closable:true" title="系统菜单">
<table>
<tr>
<td>编号</td>
<td><input type="text" id="Id" value="" class="easyui-validatebox" required="true" /></td>
</tr>
<tr>
<td>编号</td>
<td><input type="text" id="Id" value="" class="easyui-validatebox" maxlength="5" /></td>
</tr>
</table>
<a href="#" onclick="FunIns()" class="easyui-linkbutton" data-options="iconCls:'icon-save'">添加</a>
</div>
<div data-options="iconCls:'icon-remove', closable:true " title="业务菜单">内容2</div>
</div>
</div>
以上是页面的一个按钮样式和头样式
以下是httpClient的封装方法
httpClient的GET请求方法 显示数据
public List<T> EmailList<T>(string Url)
{
//定义变量接收返回数据
string Result = "";
List<T> list = new List<T>();
//实例化HttpClient
HttpClient httpClient = new HttpClient();
//设置返回数据的形式
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//定义一个变量接收GET请求返回值
HttpResponseMessage response = httpClient.GetAsync(Url).Result;
//判断值是否为空
if (response.IsSuccessStatusCode)
{
//将数据转化成流
Result = response.Content.ReadAsStringAsync().Result;
//反序列化
list = JsonConvert.DeserializeObject<List<T>>(Result);
}
//释放数据
httpClient.Dispose();
return list;
}
--------------------------------------------------
以下是拉姆达表达式和分页应用
if (name == null)
{
name = "";
}
Pages pageModel = new Pages();
string url = "";
List<Model> s = Db.EmailList(url);
pageModel.pagecount = s.Count;
pageModel.pageindex = pageIndex;
pageModel.pagesize = 1;
s = s.Where(p => p.Name.Contains("小刚")).OrderBy(p => p.ID).Skip(pageModel.pagesize * (pageModel.pageindex - 1)).Take(pageModel.pagesize).ToList();
pageModel.pageList = s;
---------------------------------------
分页页面显示
@*<div>
<table>
@foreach (var item in Model.pageList)
{
<tr>
<td>@item.ID</td>
<td>@item.Name</td>
<td>@item.Sex</td>
<td>@item.CreateTime</td>
</tr>
}
</table>*@
@*<ul class="pagination">
<li><a href="/Default1/Index?pageIndex=1">首页</a></li>
<li class="active">
@{
var h = Model.pageindex;
if (h > 1) {h = Model.pageindex - 1;}
else {h = 1;}
}
<a href="/Default1/Index?pageIndex=@h">上一页</a>
</li>
@{
int n;
if(Model.pagecount%2==0)
{
n = Model.pagecount / 2;
}
else
{
n = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(Model.pagecount / 2)) + 1);
}
for (int i = 1; i <=n; i++)
{
<li>
<a href="/Default1/Index?pageIndex=@i">@i</a>
</li>
}
}
@{
var x = Model.pageindex;
if (x < n) { x = Model.pageindex + 1; }
else
{ x = n; }
}
<li><a href="/Default1/Index?pageIndex=@x">下一页</a> </li>
<li><a href="/Default1/Index?pageIndex=@n">尾页</a></li>
</ul>
</div>*@
-----------------------------------------
redis用法
config配置
<!--Redis服务器地址-->
<add key="RedisServiceUrl" value="127.0.0.1"/>
<add key="RedisServicePortNum" value="6379"/>
------------------
需要引用 using Dbridise;
DLL的方法
public List<Modelinfo> ShowList()
{
List<Modelinfo> data =new List<Modelinfo>()
{
new Modelinfo{ID=1,Name="小明",Sex="男",CreateTime="1994"},
new Modelinfo{ID=2,Name="小",Sex="男",CreateTime="1994"},
new Modelinfo{ID=3,Name="小刚",Sex="男",CreateTime="1994"}
};
RedisHelper.Set<List<Modelinfo>>("MyModelList", data);
var res = RedisHelper.Get<List<Modelinfo>>("MyModelList");
return res;
}
---七层中的工厂
public T GetFacotry()
{
Type t=typeof(T);
T da=(T)Assembly.Load(t.Namespace).CreateInstance(t.FullName);
return da;
}
接口类
T GetFacotry();
--BLL调用
DalPerson s = new Facotrys<DalPerson>().GetFacotry();
return s.ShowList();
抽象工厂其实就是降低项目的耦合,并且把工厂抽象化,实现一个生产DAL的目的 。