Tencent / APIJSON

🏆 零代码、全功能、强安全 ORM 库 🚀 后端接口和文档零代码,前端(客户端) 定制返回 JSON 的数据和结构。 🏆 A JSON Transmission Protocol and an ORM Library 🚀 provides APIs and Docs without writing any code.
http://apijson.cn
Other
16.94k stars 2.13k forks source link

比如创建一个菜单,我想由后端赋值创建时间和创建人,请问怎么操作? #196

Closed ImagineL closed 3 years ago

ImagineL commented 3 years ago

具体说下 比如创建一个菜单,我想由后端赋值创建时间和创建人,请问怎么操作? image { "Application":{ "name":"测试应用", "appkey": "kdyh", "type": 2, "gmt_create()":"getNow()" }, "tag":"Application" }

我觉得我比较理想的方式应该是这样: "gmt_create()":"getNow()",后端就识别到赋值并写入数据库了。但是实际上,这个是将当前时间返回给前端。

求大佬帮助 [哭泣][哭泣][哭泣]

为什么 因为这个场景我太常用了。我试过远程函数调用,但是都是以response的方式返回。

TommyLemon commented 3 years ago

如果每个接口逻辑不一样,可以在你已经做到的基础上新增

"gmt_create@":"/Application/gmt_create"

当然需要保证

"gmt_create()":"getNow()" 

先执行,所以可以用优先级更高的标识:

"gmt_create-()":"getNow()" 

最终是

{
    "Application": {
        "name": "测试应用",
        "appkey": "kdyh",
        "type": 2,
        "gmt_create-()": "getNow()",
        "gmt_create@": "/Application/gmt_create"
    },
    "tag": "Application"
}

或者干脆把远程函数写在 Application 上方

{
    "gmt_create-()": "getNow()",
    "Application": {
        "name": "测试应用",
        "appkey": "kdyh",
        "type": 2,
        "gmt_create@": "gmt_create"
    },
    "tag": "Application"
}




如果是要统一处理,可以:

在重写 DemoObjectParser 重写 newSQLConfig,把从 Controller 经过 DemoParser 传过来的 gmt_create, create_time, creator_id 等 put 进去 https://github.com/APIJSON/APIJSON-Demo/blob/316b4411eec25a4fd1137fd69fb1de1171e75a57/APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/DemoObjectParser.java

        @Override
    public SQLConfig newSQLConfig(RequestMethod method, String table, String alias, JSONObject request, List<Join> joinList, boolean isProcedure) throws Exception {
               if (request != null && method == RequestMethod.POST) {
                   request.put("gmt_create", System.currentTimeInMillis());
               }
           return super.newSQLConfig(method, table, alias, request, joinList, isProcedure);
    }

参考 https://github.com/Tencent/APIJSON/issues/148#issuecomment-728653332

ImagineL commented 3 years ago

超级感谢~~~感谢大佬回复,一会就去试试~谢谢

ImagineL commented 3 years ago

非常灵活的框架~