1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using Microsoft.AspNetCore.Mvc;
  8.  
  9. namespace WebAPIForAndroid.Controllers
  10. {
  11. //[Route("api/[controller]")] //默认的路由规则
  12. //url由原来的http://localhost:59640/api/StuInFors 变成:http://localhost:59640/api/StuInFors/post/
  13. [Route("api/[controller]/[action]")]//自定义路由规则(必须指定action)
  14. [ApiController]
  15. public class StuInForsController : ControllerBase
  16. {
  17. // GET api/StuInFors
  18. [HttpGet]
  19. //public ActionResult<IEnumerable<string>> Get()
  20. public JsonResult Get()
  21. {
  22. string sql = "select top 100 * from dbo.infor";
  23. DataTable datatable = DBHelper.DBExecuteByAdapter(sql);
  24. string jsonstr = JSONInterFace.DataTableToJsonWithJsonNet(datatable);
  25. return new JsonResult(jsonstr) ;
  26. }
  27.  
  28. // GET api/StuInFors/5
  29. [HttpGet("{hno}")]
  30. public JsonResult Get(string hno)//注意:参数名称必须和路由[HttpGet("")]中的template相同,否则取不到值。
  31. {
  32. string sql = "select * from dbo.infor where [no]='" + hno + "'";
  33. DataTable datatable = DBHelper.DBExecuteByAdapter(sql);
  34. string jsonstr = JSONInterFace.DataTableToJsonWithJsonNet(datatable);
  35. return new JsonResult(jsonstr);
  36. }
  37.  
  38. // POST api/StuInFors
  39. [HttpPost]
  40. public string Post()//[FromBody] string value)
  41. {
  42. string retvalue = "addfailed";
  43. if (Request.Form.ContainsKey("androidkey"))
  44. {
  45. //既然从Form里取值了,所以不要参数:[FromBody] string value
  46. //能取到
  47. retvalue = Request.Form["androidkey"];
  48. }
  49. if (!string.IsNullOrEmpty(retvalue))
  50. {
  51. retvalue = "addsuccess";
  52. }
  53. return retvalue;
  54. }
  55.  
  56. // PUT api/StuInFors/5
  57. [HttpPut("{id}")]
  58. public void Put(int id, [FromBody] string value)
  59. {
  60. }
  61.  
  62. // DELETE api/StuInFors/5
  63. [HttpDelete("{hno}")]
  64. public void Delete(string hno)
  65. {
  66. string sql = "delete from dbo.infor where [no]='" + hno + "'";
  67. DBHelper.DBExecute(sql);
  68. }
  69. }
  70. }

部署到IIS后用Postman调用结果:

关于如何部署.net core webapi 到IIS 请看本人上一篇:https://www.cnblogs.com/longdb/p/10015302.html

.net core webapi 在原有基础上修改。的更多相关文章

  1. .Net Core WebApi在Linux上启动和关闭

    测试机器:阿里云云主机1核2g 安装环境:centos-7 服务器:Nginx 1.17.1 测试默认已启动 已安装配置:.Net Core 3.1 测试默认安装 连接配置:x-ftp,x-shell ...

  2. net core WebApi——文件分片上传与跨域请求处理

    目录 前言 开始 测试 跨域 小结 @ 前言 在之前整理完一套简单的后台基础工程后,因为业务需要鼓捣了文件上传跟下载,整理完后就迫不及待的想分享出来,希望有用到文件相关操作的朋友可以得到些帮助. 开始 ...

  3. net core WebApi——文件分片下载

    目录 前言 开始 测试 小结 @ 前言 上一篇net core WebApi--文件分片上传与跨域请求处理介绍完文件的上传操作,本来是打算紧接着写文件下载,中间让形形色色的事给耽误的,今天还是抽个空整 ...

  4. net core WebApi——使用NPOI导入导出操作

    目录 前言 NPOI 测试 小结 @ 前言 时间过得好快,在之前升级到3.0之后,就感觉好久没再动过啥东西了,之前有问到Swagger的中文汉化,虽说我觉得这种操作的意义不是太大,也是多少鼓捣了下,其 ...

  5. .net core webapi 文件上传在 Swagger 文档中的有好提示处理

    前提: 需要nuget   Swashbuckle.AspNetCore 我暂时用的是  4.01 最新版本: 描述:解决 .net core webapi 上传文件使用的是 IFormFile,在S ...

  6. .Net Core WebApi(二)在Windows服务器上部署

    上一篇学习到了如何简单的创建.Net Core Api和Swagger使用,既然写了接口,那么就需要部署到服务器上才能够正式使用.服务器主要用到了两种系统,Windows和Linux,.Net和Win ...

  7. 关于修改.net core webapi中null默认返回的状态码。

    在asp .net core webapi中,http请求的响应数据如果是null的话,我们知道状态码会返回204,即NoContent,为什么会出现这种情况呢?   因为在返回响应数据的时候,nul ...

  8. AngularJS 2调用.net core WebAPI的几个坑

    前几天,按照AngularJS2的英雄指南教程走了一遍,教程网址是http://origin.angular.live/docs/ts/latest/tutorial/. 在步骤完成后,又更进一步,在 ...

  9. Asp.Net Core WebApi学习笔记(四)-- Middleware

    Asp.Net Core WebApi学习笔记(四)-- Middleware 本文记录了Asp.Net管道模型和Asp.Net Core的Middleware模型的对比,并在上一篇的基础上增加Mid ...

随机推荐

  1. Auto Encoder

    对自编码器的理解: 对于给定的原始输入x,让网络自动找到一种编码方式(特征提取,原始数据的另一种表达),使其解码后的输出x'尽可能复现原始输入x. 知乎参考:https://www.zhihu.com ...

  2. 福大软工 · BETA 版冲刺前准备(团队) [已完成]

    写在前面 本次作业地址 林燊大哥 过去存在的问题 算法组 没有考虑到数据集不充足的情况.一开始我们将所有数据集按照8:1:1进行分割,分别分配给训练集.开发集和测试集.然鹅后来发现采集到的数据不够充足 ...

  3. Redis安装及HA(High Availability)配置(转)

    出处:http://www.cnblogs.com/morvenhuang/p/4184262.html Redis是一种内存数据库,以KEY-VALUE(即键值对)的形式存储数据.这篇文章主要介绍的 ...

  4. beecloud resrful api test(nodejs)

    直接上代码 /** * Created by wyh on 2015/10/8. * 参数说明:https://beecloud.cn/doc/ */ var https = require('htt ...

  5. java.lang.NoClassDefFoundError: Could not initialize class com解决方案

    编写的时候遇到这样一个bug, java.lang.NoClassDefFoundError: Could not initialize class com 纠结了两天多,但是,没有找到答案,这个问题 ...

  6. SpringMVC源码解读 - HandlerMapping - AbstractDetectingUrlHandlerMapping系列初始化

    AbstractDetectingUrlHandlerMapping是通过扫描方式注册Handler,收到请求时由AbstractUrlHandlerMapping的getHandlerInterna ...

  7. JS Closure 闭包

    /*一.变量的作用域要理解闭包,首先必须理解Javascript特殊的变量作用域.变量的作用域无非就是两种:全局变量和局部变量.Javascript语言的特殊之处,就在于函数内部可以直接读取全局变量. ...

  8. CodeForces 376F Tree and Queries(假·树上莫队)

    You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. We will ass ...

  9. 关于获取客户端Mac地址

    private static string GetClientMAC() { string mac_dest = string.Empty; try { string strClientIP = Ht ...

  10. 使用pycharm专业版创建虚拟环境

    Location为工程地址 D:\My_python 第二个Location为 虚拟环境放在这个工程下 Base interpreter:基于那个解释器来创建虚拟环境 Create后进入到目录查看下