您的位置:首页 > 编程语言 > ASP

【搭建Spring.net+EF+Asp.net MVC框架】---(2)Demo实现

2017-12-27 20:23 656 查看

前言

上一篇咱们已经建立好了整个Spring.net的框架,这篇文件来为框架添加各层的实现方法。

添加各层引用

DAL层引:IDAL,Model

BLL引用IBLL:IDAL,Model

SpringMVCTest引用:IBLL,BLL

实现D层和B层

第一步:设计IDAL,添加接口IUserDAL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IDAL
{
public interface IUserDAL        //D层接口
{
bool isExist(int userid);
}
}


第二步:设计D层接口实现,添加实现类UserDAL,为了简单的体现他们之间的关系,这里没有连接数据库,仅仅在D层写了一个简单的判断,如果用户在表示层页面输入非0数字则返回true,输入0则返回false。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IDAL;

namespace DAL
{
public class UserDAL : IUserDAL  //实现D层接口
{
public bool isExist(int userid)
{
if (userid == 0)
{
return false;
}
else
{
return true;
}
}
}
}


第三步:添加B层接口IUserBLL,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IBLL
{
public  interface IUserBLL  //B层接口
{
bool isExist(int userid);
}
}


第四步:添加B层接口实现类 UserBLL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IBLL;
using IDAL;

namespace BLL
{
public class UserBLL:IUserBLL      //实现B层接口
{
IUserDAL idal { get; set; }
public bool isExist(int userid)
{
return idal.isExist(userid);
}
}
}


表示层传入数据

HelloController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BLL;
using IBLL;

namespace SpringMvcTest.Controllers
{
public class HelloController : Controller
{

IUserBLL iuserbll { get; set; }

public ActionResult Index()
{
return View();
}

public bool isExist(int userid)
{
return iuserbll.isExist(userid);
}

}
}


Index:

@{
ViewBag.Title = "Index";
}

<h2>Index</h2>
<html>
<head>
<title>yiyiyi</title>
<script src="~/JS/jquery-1.7.2.min.js"></script>
</head>

<body>
<span>  用户名: </span> <input type="text" id="txtuserid"  />
<input type="button"  value="是否存在"  id="btnOK" onclick="isExist()" />
</body>
</html>

<script type="text/javascript">
function isExist() {
var a = document.getElementById("txtuserid").value     //JS 根据dom节点获得值
$.ajax({
type: 'post',
url: "/Hello/isExist",
data: "&userid=" + a,
success: function (data) {
if (data == "True") {
alert("存在");
}
else {
alert("不存在");
}
}
})
}
</script>


到这里,各层该有的方法已经有了,但是还缺一项Spring.net中最重要的配置文件,感谢阅读,下次分享配置文件的设置。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐