Ajax +SpringMVC 请求后台数据

前端之家收集整理的这篇文章主要介绍了Ajax +SpringMVC 请求后台数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、目标

通过Ajax 请求后台数据

二、代码

1、前台ftl文件,通过URL请求后台数据,返回数据(Json格式)封装在data中

[#ftl]
[#include "/_inc/inc.ftl"]

<html>
   <head>
      <title>打印页面</title>
        [#include "/_inc/Meta.ftl"]
    	[#include "/_inc/css.ftl"]
    	[#include "/_inc/link.ftl"]
   </head>

<body onload="getJudgeId()">
		<h3>打印进行中</h3>
</body>

<script type="text/javascript">
	 function getJudgeId()
	 { 
		$.get("${ctxPath}/common/waiting/task/usedcar/judge/id",{
 
		},function(data){
			
			if(data.status){
				var url="${ctxPath}/common/print/usedcar/judge/" + data.judgeId + "/0";
				printPreview(url);
			}
		});
	 }  

	 setInterval("getJudgeId()",1000*10);

</script>
</html> 


 2、SpringMVC controller 
 
	@RequestMapping(value = "common/waiting/task/usedcar/judge/id",method = RequestMethod.GET)
	public  @ResponseBody ModelAndView getShopInJSON() { 
		FastJsonJsonView view = new FastJsonJsonView();
		String judgeId = this.usedCarJudgePrintTaskService.getEarlyTaskJudgeIdByStatus("0");
		Boolean status = false;
		if(judgeId!=null&&judgeId.length()!=0){
			status = true;
			view.addStaticAttribute("status",status);
			view.addStaticAttribute("judgeId",judgeId);
		}else{
			view.addStaticAttribute("status",status);
		}
		return new ModelAndView(view);
	}		
原文链接:https://www.f2er.com/springmvc/162995.html

猜你在找的SpringMVC相关文章