大佬教程收集整理的这篇文章主要介绍了从Spring MVC Controller返回JSON或View,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@requestMapPing(value="/users", method=requestMethod.POST)
public Object index(@requestbody SearchUsersviewmodel model, httpServletResponse responsE) {
model.setList(userservice.getUsers(model));
if(true)
{
return new ModelAndVIEw("controls/tables/users", "model", model);
}
else
{
return JsonVIEw.Render(model, responsE);
}
}
@H_801_2@JsonVIEw.java
public class JsonVIEw {
public static ModelAndVIEw Render(Object model, httpServletResponse responsE)
{
MapPingJacksonhttpmessageConverter JsonConverter = new MapPingJacksonhttpmessageConverter();
MediaType JsonMimeType = MediaType.APPliCATION_JsON;
try {
JsonConverter.write(model, JsonMimeType, new ServletServerhttpResponse(responsE));
} catch (httpmessageNotWritableException E) {
e.printstacktrace();
} catch (IOException E) {
e.printstacktrace();
}
return null;
}
}
@H_801_2@进行呼叫的Js函数
config.request = $
.AJAX({
url : url,
data : $.toJsON(def.data),
type : def.type,
dataType : def.dataType,
processData : true,
ContentType : def.ContentType,
success : function(data) {
try {
var Json = data;
if (typeof data === "String" || typeof data == "String") {
Json = (eval('(' + data + ')'));
}
if ('object' === typeof Json) {
if (Json.ValIDation && Json.ValIDation.Errors.length > 0) {
$.each(Json.ValIDation.Errors, function() {
// Error Code check
});
// Error CallBACk
if (typeof (def.errorCallBACk) == 'function') {
def.errorCallBACk(Json);
}
} else {
def.callBACk(data);
}
} else {
def.callBACk(data);
}
} catch (E) {
def.callBACk(data);
// HIDe Loading
}
},
error : function(data) {
}
});
以上是大佬教程为你收集整理的从Spring MVC Controller返回JSON或View全部内容,希望文章能够帮你解决从Spring MVC Controller返回JSON或View所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。