1、ajax請求數據類類型dataType 必須爲jsonp
2、請求的接口必須要使用SSO 的客戶端進行驗證
3、請求的接口返回類型不能爲Map<key,value>對象(試過不成功),改爲View 對象才成功,對於能否返回String 類型沒驗證。
示例:
項目A 中ajax請求:
$.ajax({
url:"項目B的某個服務接口",
type:"GET",
dataType:"jsonp",
data:{page:1,pageSize:10,queryString:null},
success:function(data){
//。。。
}
});
項目B的服務接口:
@RequestMapping(value="/getData",method=RequestMethod.GET)
public View getBeans(
@RequestParam(required=false) Long page,
@RequestParam(required=false) Long pageSize,
@RequestParam(required=false) String queryConfig,
HttpServletRequest req,HttpServletResponse resp,Model model){
UserVo user = new UserVo();
try {
//必須調用SSO 客戶端驗證,不管成功與否
user = AuthenticateInfoUtil.getAuthenticateUserInfo(req, resp, null);
if(user == null){
model.addAttribute("mes", "用戶未登錄,不能進行此操作!");
model.addAttribute("status", SERVER_STATUS_FAILED);
return JSON;
}
}catch(Exception e){
System.out.println("異常");
}
user.setUser_id(1L);
user.setUser_name("system");
user.setOrganization_id(1L);
user.setOrganization_name("組織名");
// 返回類型不能爲Map對象,此處JSON 爲MappingJackson2JsonView 實例
return JSON;
}