比如,一个检索页面,有几个条件选择,检索条件有:类型,数值比如可以选择1,2,3;状态,数值也有1,2,3,我必须在后台定义一个检索条件的Pojo吗?
问答
在页面ajax提交自定义json,在后台用Json适配器的话,必须要定义对应的pojo吗?
标签:
无
29 回复
如果传过来的json是这样的格式的呢?用NutMap吗?
{
type:2,
status:3,
timeperiods:{startDate:2005-01-01,endDate:2017-01-30}
}
现在报这个错了
2017-04-17 23:36:25,950 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) DEBUG - [GET ]URI=/public/wx/ins/myorders 252ms
17-Apr-2017 23:36:33.399 信息 [http-nio-8080-exec-9] org.apache.coyote.http11.Http11Processor.service Error parsing HTTP request header
Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:467)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:667)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:789)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1437)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
我是用的例子里的示例代码,不应该有不安全字符啊。
$.ajax({
url: 'myorders',
"data": JSON.stringify(params), // 注意要转为json,除非data本身就是json字符串
dataType: 'json',
success: function (params) {
console.log(params);
}
});
生成的URL是这个
http://xxxxx.ngrok.wendal.cn/public/wx/ins/myorders?{%22type%22:%221%22,%22status%22:%222%22,%22timeperiods%22:{%22startDate%22:%22%22,%22endDate%22:%22%22}}
对应的@At应该怎么写?
我现在用@Param("type") Map<String, String> insType, @Param("status") Map<String, String> orderStatus,....这样的map去接受参数,取到的参数都是null。哪里的问题?
$.ajax({
url: 'myorders',
"data": JSON.stringify(params), // 注意要转为json,除非data本身就是json字符串
dataType: 'json',
type: 'POST',
success: function (params) {
console.log(params);
}
});
@AdaptBy(type=JsonAdaptor.class)
@At("/myorders")
public void myorders(@Param("type") Map<String, String> insType, @Param("status") Map<String, String> orderStatus, @Param("timeperiods") Map<String, String> timeperiod, HttpServletRequest req, HttpSession session)
public void myorders(@Param("..") Map<String, Object> params, HttpServletRequest req, HttpSession session)
另外, params的内容是啥
方法改成了这样,但是params取到的还是null呢
public void myorders(@Param("..") Map<String, Object> params, HttpServletRequest req, HttpSession session)
有一种可能性, 被其他代码给吃了
$.ajax({
url: 'myorders',
"data": JSON.stringify(params),
dataType: 'json',
contentType: "application/json", // 加这行,确保不会被吃掉.
type: 'POST',
success: function (re) {
console.log(re);
}
});
我现在用这个参数列表也可以取到相应的值了,哪种方式是比较推荐的?
public void myorders(@Param("type") String insType, @Param("status") String orderStatus, @Param("timeperiods") Map timeperiod, HttpServletRequest req, HttpSession session) {
@wendal @qq_df433f5d 我有跟你类似的情况,也是一样@Param(‘target’)Role role 和 @Param('target) Permission per , role 可以获取到数据,per 不行。。
@POST
@AdaptBy(type=JsonAdaptor.class)
@RequiresPermissions("authority:permission:add")
@At("/permission/add")
public void addPermission(@Param("target")Permission permission) {
if (permission == null)
return;
dao.insert(permission);
}
@POST
@AdaptBy(type=JsonAdaptor.class)
@RequiresPermissions("authority:role:add")
@At("/role/add")
public void addRole(@Param("target")Role role) {
if (role == null)
return;
dao.insert(role); // 注意,这里并没有用insertWith, 即总是插入一个无权限的角色
}
页面上调用的是同一个方法, param 就是存放数据的 json {name: '123', alias: 'aaa'} 这一类的
this.to({target: para}).then((res) => {
this.loading = false
NProgress.done()
this.$notify(util.notifyBody(true, '提交完成'))
this.$refs['commonForm'].resetFields()
this.visible = false
this.fields = []
this.callback()
})
@wendal 没有传错,都是类似 {id: "", name: "test permission", alias: "测试权限", description: "123"} 这样的数据,好奇怪
@wendal 莫名奇妙可以了,我把 permission 改成role ,然后运行了一遍可以接收到数据,然后改回permission重启,现在permission也可以接收到数据了。。。
添加回复
请先登陆