Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 25fe655

Browse files
committed
#增加函数调用#
1 parent f212872 commit 25fe655

File tree

6 files changed

+60
-7
lines changed

6 files changed

+60
-7
lines changed

‎APIJSON.NET/APIJSON.NET.Test/APIJSON.NET.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<PackageReference Include="JsonApiFramework.Server" Version="1.7.0" />
910
<PackageReference Include="RestSharp" Version="106.3.1" />
1011
</ItemGroup>
1112

‎APIJSON.NET/APIJSON.NET.Test/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using RestSharp;
1+
using JsonApiFramework.Server;
2+
using RestSharp;
23
using System;
34

45
namespace APIJSON.NET.Test
@@ -41,7 +42,7 @@ static void Main(string[] args)
4142
IRestResponse response2 = client.Execute(request);
4243
Console.WriteLine(response2.Content);
4344

44-
45+
4546
Console.ReadLine();
4647
}
4748
}

‎APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using SqlSugar;
1111
using System.Linq;
1212
using APIJSON.NET.Services;
13-
13+
usingSystem.Reflection;
1414

1515
[Route("api/[controller]")]
1616
[ApiController]
@@ -27,6 +27,7 @@ public JsonController(SelectTable _selectTable, DbContext _db,IIdentityService i
2727
db = _db;
2828
_identitySvc = identityService;
2929
}
30+
3031
/// <summary>
3132
/// 查询
3233
/// </summary>
@@ -64,11 +65,11 @@ public ActionResult Query([FromBody]string json)
6465
{
6566
string table = tables[0];
6667
var temp = selectTable.GetTableData(table, page, count, where[0], null);
67-
if (query >0)
68+
if (query >0)
6869
{
6970
total = temp.Item2;
7071
}
71-
72+
7273
foreach (var dd in temp.Item1)
7374
{
7475
var zht = new JObject();
@@ -125,6 +126,34 @@ public ActionResult Query([FromBody]string json)
125126
}
126127
ht.Add(key, htt);
127128
}
129+
else if (key.Equals("func"))
130+
{
131+
jb = JObject.Parse(item.Value.ToString());
132+
Type type = typeof(MethodList);
133+
Object obj = Activator.CreateInstance(type);
134+
var bb = new JObject();
135+
foreach (var f in jb)
136+
{
137+
var types = new List<Type>();
138+
var param = new List<string>();
139+
foreach (var va in JArray.Parse(f.Value.ToString()))
140+
{
141+
types.Add(typeof(string));
142+
param.Add(va.ToString());
143+
}
144+
MethodInfo mt = type.GetMethod(f.Key, types.ToArray());
145+
if (mt == null)
146+
{
147+
bb.Add(f.Key, "没有获取到相应的函数!");
148+
}
149+
else
150+
{
151+
bb.Add(f.Key, JToken.FromObject(mt.Invoke(obj, param.ToArray())));
152+
}
153+
154+
}
155+
ht.Add("func", bb);
156+
}
128157
else if (key.IsTable())
129158
{
130159
var template = selectTable.GetFirstData(key, item.Value.ToString(), ht);
@@ -137,6 +166,7 @@ public ActionResult Query([FromBody]string json)
137166
{
138167
ht.Add("total", total);
139168
}
169+
140170
}
141171
}
142172
catch (Exception ex)

‎APIJSON.NET/APIJSON.NET/MethodList.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace APIJSON.NET
7+
{
8+
public class MethodList
9+
{
10+
public string Merge(string a, string b)
11+
{
12+
return a + b;
13+
}
14+
public object MergeObj(string a, string b)
15+
{
16+
return new { a, b };
17+
}
18+
}
19+
}

‎APIJSON.NET/APIJSON.NET/appsettings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"ConnectionStrings": {
3-
"DbType": 1, //0:MySql,1:SqlServer,2:Sqlite
4-
"ConnectionString": "Server=liaozengbo\\sql2018; Database=test; User Id=sa;Password=sa123;"
3+
"DbType": 0, //0:MySql,1:SqlServer,2:Sqlite
4+
//"ConnectionString": "Server=liaozengbo\\sql2018; Database=test; User Id=sa;Password=sa123;",
5+
"ConnectionString": "Server=localhost; Database=test; User Id=root;Password=password;charset=UTF8;"
56
},
67
"Authentication": {
78
"JwtBearer": {

‎APIJSON.NET/APIJSON.NET/wwwroot/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<option value="add">add</option>
3636
<option value="edit">edit</option>
3737
<option value="remove">remove</option>
38+
<option value="getmethod">method</option>
3839
</select>
3940
<button @click="hpost()">发送请求</button>
4041
</div>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /