.net core webapi 在原有基础上修改。
- 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 在原有基础上修改。的更多相关文章
- .Net Core WebApi在Linux上启动和关闭
测试机器:阿里云云主机1核2g 安装环境:centos-7 服务器:Nginx 1.17.1 测试默认已启动 已安装配置:.Net Core 3.1 测试默认安装 连接配置:x-ftp,x-shell ...
- net core WebApi——文件分片上传与跨域请求处理
目录 前言 开始 测试 跨域 小结 @ 前言 在之前整理完一套简单的后台基础工程后,因为业务需要鼓捣了文件上传跟下载,整理完后就迫不及待的想分享出来,希望有用到文件相关操作的朋友可以得到些帮助. 开始 ...
- net core WebApi——文件分片下载
目录 前言 开始 测试 小结 @ 前言 上一篇net core WebApi--文件分片上传与跨域请求处理介绍完文件的上传操作,本来是打算紧接着写文件下载,中间让形形色色的事给耽误的,今天还是抽个空整 ...
- net core WebApi——使用NPOI导入导出操作
目录 前言 NPOI 测试 小结 @ 前言 时间过得好快,在之前升级到3.0之后,就感觉好久没再动过啥东西了,之前有问到Swagger的中文汉化,虽说我觉得这种操作的意义不是太大,也是多少鼓捣了下,其 ...
- .net core webapi 文件上传在 Swagger 文档中的有好提示处理
前提: 需要nuget Swashbuckle.AspNetCore 我暂时用的是 4.01 最新版本: 描述:解决 .net core webapi 上传文件使用的是 IFormFile,在S ...
- .Net Core WebApi(二)在Windows服务器上部署
上一篇学习到了如何简单的创建.Net Core Api和Swagger使用,既然写了接口,那么就需要部署到服务器上才能够正式使用.服务器主要用到了两种系统,Windows和Linux,.Net和Win ...
- 关于修改.net core webapi中null默认返回的状态码。
在asp .net core webapi中,http请求的响应数据如果是null的话,我们知道状态码会返回204,即NoContent,为什么会出现这种情况呢? 因为在返回响应数据的时候,nul ...
- AngularJS 2调用.net core WebAPI的几个坑
前几天,按照AngularJS2的英雄指南教程走了一遍,教程网址是http://origin.angular.live/docs/ts/latest/tutorial/. 在步骤完成后,又更进一步,在 ...
- Asp.Net Core WebApi学习笔记(四)-- Middleware
Asp.Net Core WebApi学习笔记(四)-- Middleware 本文记录了Asp.Net管道模型和Asp.Net Core的Middleware模型的对比,并在上一篇的基础上增加Mid ...
随机推荐
- Auto Encoder
对自编码器的理解: 对于给定的原始输入x,让网络自动找到一种编码方式(特征提取,原始数据的另一种表达),使其解码后的输出x'尽可能复现原始输入x. 知乎参考:https://www.zhihu.com ...
- 福大软工 · BETA 版冲刺前准备(团队) [已完成]
写在前面 本次作业地址 林燊大哥 过去存在的问题 算法组 没有考虑到数据集不充足的情况.一开始我们将所有数据集按照8:1:1进行分割,分别分配给训练集.开发集和测试集.然鹅后来发现采集到的数据不够充足 ...
- Redis安装及HA(High Availability)配置(转)
出处:http://www.cnblogs.com/morvenhuang/p/4184262.html Redis是一种内存数据库,以KEY-VALUE(即键值对)的形式存储数据.这篇文章主要介绍的 ...
- beecloud resrful api test(nodejs)
直接上代码 /** * Created by wyh on 2015/10/8. * 参数说明:https://beecloud.cn/doc/ */ var https = require('htt ...
- java.lang.NoClassDefFoundError: Could not initialize class com解决方案
编写的时候遇到这样一个bug, java.lang.NoClassDefFoundError: Could not initialize class com 纠结了两天多,但是,没有找到答案,这个问题 ...
- SpringMVC源码解读 - HandlerMapping - AbstractDetectingUrlHandlerMapping系列初始化
AbstractDetectingUrlHandlerMapping是通过扫描方式注册Handler,收到请求时由AbstractUrlHandlerMapping的getHandlerInterna ...
- JS Closure 闭包
/*一.变量的作用域要理解闭包,首先必须理解Javascript特殊的变量作用域.变量的作用域无非就是两种:全局变量和局部变量.Javascript语言的特殊之处,就在于函数内部可以直接读取全局变量. ...
- 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 ...
- 关于获取客户端Mac地址
private static string GetClientMAC() { string mac_dest = string.Empty; try { string strClientIP = Ht ...
- 使用pycharm专业版创建虚拟环境
Location为工程地址 D:\My_python 第二个Location为 虚拟环境放在这个工程下 Base interpreter:基于那个解释器来创建虚拟环境 Create后进入到目录查看下