Tencent/APIJSON

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

ImagineL opened this issue · 3 comments

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

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

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

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

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

"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);
 	}

参考
#148 (comment)

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

非常灵活的框架~