AngularJs错误:Error: [$resource:badcfg] Error in resource configuration

在$Resource调用后台服务的时候发生下面的错误:



下面是程序源代码:

服务:listViewApp.factory('ReportviewService',function($resource)
		{
			var reportviewService = $resource('/DDD3/ReportView/:action',{});
			
			reportviewService.findColumns=function(dataSourceId,sucesscb,errorcb)
			{
				reportviewService.get({action:'findColumns',dataSourceId:+dataSourceId},sucesscb,errorcb);
			}
			
			return reportviewService;
		})
调用:ReportviewService.findColumns($stateParams.id,function(data){$scope.columns=data;},$scope.errorFind);

后台代码:import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.alibaba.fastjson.JSONObject;
import com.cqut.genhoo.annotation.Action;
import com.cqut.genhoo.annotation.RequestMapping;
import com.cqut.genhoo.annotation.RequestParam;

import ddd.base.exception.DDDException;
import ddd.simple.service.listview.ReportViewService;

@Action
@RequestMapping("/ReportView")
@Controller
public class ReportViewAction
{
	
	@Resource(name="reportViewServiceBean")
	private ReportViewService reportViewService;
	
	public String findColumns(@RequestParam("dataSourceId")Long dataSourceId)
	{
		try {
			Set<Map<String, Object>> ColumnMetaData = this.reportViewService.findColumns(dataSourceId);
			return JSONObject.toJSONString(ColumnMetaData);
		} catch (DDDException e) {
			return JSONObject.toJSONString(e);
		}
	}
}


解决:

问题解释:错误:[$Resource:badcfg]在资源配置中的错误。 预计响应包含一个数组,但得到了一个对象

问题分析:$Resource.get()得到的返回值为对象,详见http://docs.ngnice.com/api/ngResource/service/$resource

解决方案:更改服务如下:

listViewApp.factory('ReportviewService',function($resource)
		{
			var reportviewService = $resource('/DDD3/ReportView/:action',{});
			
			reportviewService.findColumns=function(dataSourceId,sucesscb,errorcb)
			{
				reportviewService.<span style="color:#ff6666;">query</span>({action:'findColumns',dataSourceId:+dataSourceId},sucesscb,errorcb);//将get改为query
			}
			
			return reportviewService;
		})

阅读更多

没有更多推荐了,返回首页