这里拿一个接口举例,实现返回企业列表。
IEnumerable<T>解读:https://bbs.csdn.net/topics/392147930
返回 IEnumerable<T>
[HttpGet] public ResponseJson<IEnumerable<Enterprises>> GetEnterPriseByKey(String EnterprisID) { ResponseJson<IEnumerable<Enterprises>> json = null; try { var EnterModel = conn.Query<Enterprises>("select * from Enterprises where EnterprisID=@EnterprisID",new { EnterprisID = EnterprisID }); json = new ResponseJson<IEnumerable<Enterprises>>(ResponseCode.Nomal, EnterModel); } catch (Exception ex) { json = new ResponseJson<IEnumerable<Enterprises>>(ResponseCode.Err, ex.Message); } return json; }
返回 List
[HttpGet] public ResponseJson<List<Enterprises>> GetEnterpriseList() { ResponseJson<List<Enterprises>> json = null; try { List<Enterprises> EnteListVar = conn.Query<Enterprises>("select * from Enterprises").ToList(); json = new ResponseJson<List<Enterprises>>(ResponseCode.Nomal, EnteListVar); } catch(Exception ex) { json = new ResponseJson<List<Enterprises>>(ResponseCode.Err, ex.Message); } return json; }