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. [Training Video - 3] [Groovy in Detail] Non-static and Static variables, objects and object referances

    log.info "starting" // we use class to create objects of a class Planet p1 = new Planet() ...

  2. servletConfig的应用

    在Servlet的配置文件中,可以使用一个或多个<init-param>标签为servlet配置一些初始化参数. 当servlet配置了初始化参数后,web容器在创建servlet实例对象 ...

  3. C# chart.DataManipulator.FinancialFormula()公式的使用 线性回归预测方法

    最近翻阅资料,找到 chart.DataManipulator.FinancialFormula()公式的使用,打开另一扇未曾了解的窗,供大家分享一下. 一 DataManipulator类 运行时, ...

  4. Spring框架总结(三)

    SpringIOC容器 一.创建对象 SpringIOC容器,是spring核心内容. 作用: 创建对象 & 处理对象的依赖关系 IOC容器创建对象: 创建对象, 有几种方式: 1) 调用无参 ...

  5. java.lang.ClassCastException: com.liuyang.annocation.UserAction cannot be cast to com.liuyang.annocation2.UserAction at com.liuyang.annocation2.App.test

    java.lang.ClassCastException: com.liuyang.annocation.UserAction cannot be cast to com.liuyang.annoca ...

  6. SpringMVC源码解读 - RequestMapping注解实现解读 - RequestMappingInfo

    使用@RequestMapping注解时,配置的信息最后都设置到了RequestMappingInfo中. RequestMappingInfo封装了PatternsRequestCondition, ...

  7. ENVI 图像特征提取

  8. 编写高质量代码改善C#程序的157个建议——建议80:用Task代替ThreadPool

    建议80:用Task代替ThreadPool ThreadPool相对于Thread来说具有很多优势,但是ThreadPool在使用上却存在一定的不方便.比如: ThreadPool不支持线程的取消. ...

  9. JAVA并发设计模式学习笔记(二)—— Single Threaded Execution Pattern

    注:本文的主要参考资料为结城浩所著<JAVA多线程设计模式>. 单线程执行模式(Single Threaded Execution Pattern)是最简单的多线程设计模式,几乎所有其他的 ...

  10. 阿里云vsftp安装和简单的配置

    1.系统环境 [root@jie ~]# cat /etc/redhat-release CentOS release 6.8 (Final) [root@jie ~]# [root@jie ~]# ...