@ActionKey("/workflow/add") public void add() { String readData = HttpKit.readData(getRequest()); System.out.println(readData); Workflow workflow1 = JSONObject.parseObject(readData, Workflow.class); Object params = getParams(); Workflow workflow = JSONObject.parseObject(getParams().toString(), Workflow.class); boolean save = workflow.save(); if (save) { renderJson(result.success("新增workflow成功",workflow)); } else { renderJson(result.success("新增workflow失败",workflow)); } }
当访问到这个请求时,在add方法上通过
HttpKit.readData(getRequest());
是可以拿到数据的,但是,当将方法封装到
public class BaseController extends Controller { public Result result = new Result(); public Object getParams () { String method = getRequest().getMethod(); switch (method){ case "POST": String readData = HttpKit.readData(getRequest()); return readData; case "GET": return getParaToInt(); default: return null; } } }
String readData = HttpKit.readData(getRequest());
这时候拿不到数据,上面add方法所在的controller是extends BaseController的。
我是通过curl命令请求数据的
通过什么方式取数据,完全取决于客户端发送方式,例如,你用 curl 发送的方式可能是问号挂参或者是 form 表单模拟,这种全是用 getPara()