using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; namespace WebAPIForAndroid.Controllers
{
//[Route("api/[controller]")] //默认的路由规则
//url由原来的http://localhost:59640/api/StuInFors 变成:http://localhost:59640/api/StuInFors/post/
[Route("api/[controller]/[action]")]//自定义路由规则(必须指定action)
[ApiController]
public class StuInForsController : ControllerBase
{
// GET api/StuInFors
[HttpGet]
//public ActionResult<IEnumerable<string>> Get()
public JsonResult Get()
{
string sql = "select top 100 * from dbo.infor";
DataTable datatable = DBHelper.DBExecuteByAdapter(sql);
string jsonstr = JSONInterFace.DataTableToJsonWithJsonNet(datatable);
return new JsonResult(jsonstr) ;
} // GET api/StuInFors/5
[HttpGet("{hno}")]
public JsonResult Get(string hno)//注意:参数名称必须和路由[HttpGet("")]中的template相同,否则取不到值。
{
string sql = "select * from dbo.infor where [no]='" + hno + "'";
DataTable datatable = DBHelper.DBExecuteByAdapter(sql);
string jsonstr = JSONInterFace.DataTableToJsonWithJsonNet(datatable);
return new JsonResult(jsonstr);
} // POST api/StuInFors
[HttpPost]
public string Post()//[FromBody] string value)
{
string retvalue = "addfailed";
if (Request.Form.ContainsKey("androidkey"))
{
//既然从Form里取值了,所以不要参数:[FromBody] string value
//能取到
retvalue = Request.Form["androidkey"];
}
if (!string.IsNullOrEmpty(retvalue))
{
retvalue = "addsuccess";
}
return retvalue;
} // PUT api/StuInFors/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
} // DELETE api/StuInFors/5
[HttpDelete("{hno}")]
public void Delete(string hno)
{
string sql = "delete from dbo.infor where [no]='" + hno + "'";
DBHelper.DBExecute(sql);
}
}
}

部署到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. [SoapUI] 在某个测试步骤下面增加Script Assertion,运用 messageExchange 获取response content

    import com.eviware.soapui.support.GroovyUtils import com.eviware.soapui.support.XmlHolder import org ...

  2. ant+proguard签名打包 .jar

    ant+proguard签名打包 .jar 摘自: https://blog.csdn.net/a_ycmbc/article/details/53432812 2016年12月02日 14:52:3 ...

  3. tomcat启动报错:java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException:

    tomcat日志: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start com ...

  4. qt下的跨目录多工程编译(转)

    这里要编译的工程包含一个库和一个可执行文件.可执行文件依赖于库,所以要先编译库,编译后库放在lib目录里面,可执行文件放在bin目录里面. 目录结构如下: 全局的工程文件complex.pro在工程根 ...

  5. 如何使用office2016发布CSDN博客

    目前大部分的博客作者在用Word写博客这件事情上都会遇到以下3个痛点: 1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.使用Word写 ...

  6. Discuz!X2截屏控件手动安装教程-Xproer.ScreenCapture

    版权所有 2009-2015 荆门泽优软件有限公司 保留所有权利 官方网站:http://www.ncmem.com 官方博客:http://www.cnblogs.com/xproer 产品首页:h ...

  7. Joomla3x-CKEditor4x-WordPaster整合示例

    1.1. 集成到Joomla_3.4.7-ckeditor4x 资源下载:Joomla 3x,   1.1.1. 添加wordpaster文件夹 路径:/media/wordpaster/   1.1 ...

  8. 在Chrome 39中无法使用插件

    在chrome 42+版本中在开启npapi选项.   1.打开插件面板,在地址栏中输入 chrome://plugins   2.找到npScreenCapture插件,点击始终允许选框 3允许控件

  9. hibernate:对于java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I错误解决办法

    在J2EE框架下开发web网站,这种问题经常遇到,只要我们网上搜一下,就可以看到很多版本的,我整理一下:  第一种可能性解决:看看我的项目:主要 是里面的Structs 1.3 (structs 2) ...

  10. GitHub上创建组织

    4.3. 组织和团队 GitHub 在早期没有专门为组织提供账号,很多企业用户或大型开源组织只好使用普通用户账号作为组织的共享账号来使用.后来,GitHub推出了组织这一新的账号管理模式,满足大型开发 ...