1、只要action的名字等于HTTP请求动作的名称或action的名字是以http请求动作名称开头命名的都能匹配
2、POST请求用来做添加 PUT用来做修改 GET用来做查询
3、默认约束基础类型的参数通过URL传递(int,string,double等)复合类型的参数通过请求体传递
特点:1、URL只能要体现要操作的资源名称
2、对资的操作在http请求的动作上体现出来
3、Post--添加 Get--查询 Put--修改 Delete--删除
2、POST请求用来做添加 PUT用来做修改 GET用来做查询
3、默认约束基础类型的参数通过URL传递(int,string,double等)复合类型的参数通过请求体传递
特点:1、URL只能要体现要操作的资源名称
2、对资的操作在http请求的动作上体现出来
3、Post--添加 Get--查询 Put--修改 Delete--删除
满足以上三个特点的借口叫做 rest风格的接口 rest api
//创建一个API控制器(Controller)
public class RoleController : ApiController
{
IRoleBll bll = new RoleBll();
//查询Role表里的全部数据
public List<Role> Get()
{
List<Role> list = bll.Search(null);
return list;
}
//往Role表里添加数据
public object Post(Role model)
{
string msg;
bool isOK = bll.Add(model, out msg);
return new { state=isOK};
}
//通过ID修改Role表里的数据
public object Put(int id,Role model)
{
string msg;
model.ID = id;
bool isOk = bll.Update(model, out msg);
return new { state = isOk };
}
//通过id查询Role里的某条数据
public Role GetOne(int id)
{
Role model = bll.Search(id);
return model;
}
//删除
public object Delete(int id)
{
string msg;
bool isOk = bll.Delete(id, out msg);
return new { state = isOk };
}
}