3

搭建一个简易框架 3秒创建一个WebApi接口 - 风中起舞

 1 year ago
source link: https://www.cnblogs.com/zj19940610/p/17376659.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

搭建一个简易框架 3秒创建一个WebApi接口

前端ajax请求数据,传递的参数都是一个json字符串,经过多次解析发现其实都是一个DataSet
{"selectA1":[{"Name":"156324"}]}
{"selectA1":[{"Name":"156324"}],"selectA2":[{"IdA":"11","IdB":"12"},{"IdA":"13","IdB":"14"}]}
既然如此那么数据库设计一张表
872333-20230506104953031-1182521586.jpg
.
.
前端请求数据时传递一个字符串JsonParm,里面放json格式的DataSet
后台获取到字符串参数JsonParm,解析为DataSet

image
.
.
每个DataSet中的DataTable都有TableName【selectA1,selectA2】
根据selectA1查询获取对应的sql语句 select * from Test WHERE Name = @Name
image
.
.
然后把DataTable中的数据 {"Name":"156324"} 当做SqlParameter参数传递
就可以获取对应的数据了
image
.
.
获取到的数据可以自己的业务返回对应的json数据
image
image
.
.
源码已上传到 https://github.com/zj-1994/PMApi
数据库创建可以参考 https://www.cnblogs.com/zj19940610/p/12049470.html 中的 根据表名生成增删改查+分页存储过程语句

还有一个小工具调用的百度翻译 根据汉字生成对应的sql server创建表的sql语句【可问我要源码】
https://files.cnblogs.com/files/zj19940610/生成表.zip?t=1683342614&download=true

image

本文作者:风中起舞

本文链接:https://www.cnblogs.com/zj19940610/p/17376659.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @ 2023-05-06 11:05  风中起舞  阅读(564)  评论(7)  编辑  收藏  举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK