我有一个像这样的控制器
@Controller
public class EditCategoriesController {
@Autowired
ICruxPanelClientService iCruxPanelClientService;
@Autowired
private TmplUrlFetchService tmplUrlFetchService;
private static String cruxClientUrl;
private ApiEndPoints apiEndPoints;
@PostConstruct
public void init() {
try {
apiEndPoints = tmplUrlFetchService.getUrlFromConfigFile();
} catch (IOException e) {
System.out.println(e.toString());
}
cruxClientUrl = apiEndPoints.getCruxClientUrl();
}
private static int cat_id;
private static String cat_catkey;
private static int cat_index_order;
private static ArrayList<ServiceMaster> serviceMaster;
@RequestMapping(value = "/editCategories", method = RequestMethod.GET)
public String editCategories(HttpServletRequest request, Map<String, ArrayList<String>> map, Map<String, Integer> map1) {
iCruxPanelClientService.setCruxWebServiceBaseURL(cruxClientUrl);
GetCategoriesListResponse response = iCruxPanelClientService.getCategories(new GetCategoriesListRequest());
ArrayList<CategoryModel> categoryModel = response.getCategoryModels();
ArrayList<String> categoryname = new ArrayList<String>();
for (int i = 0; i < categoryModel.size(); i++) {
CategoryModel m = categoryModel.get(i);
categoryname.add(m.getName());
}
map.put("category", categoryname);
return "editCategories/editCategories";
}
@RequestMapping(value = "/printCategoryDetails", method = RequestMethod.GET, produces = "application/json")
public
@ResponseBody
Category printCategoryDetails(HttpServletRequest request) {
String res = request.getParameter("categor");
System.out.println(res);
iCruxPanelClientService.setCruxWebServiceBaseURL(cruxClientUrl);
GetCategoriesListResponse response = iCruxPanelClientService.getCategories(new GetCategoriesListRequest());
ArrayList<CategoryModel> categoryModel = response.getCategoryModels();
CategoryModel m = null;
for (int i = 0; i < categoryModel.size(); i++) {
m = categoryModel.get(i);
String name = m.getName();
if (name.equals(res)) {
break;
}
}
Category c = new Category();
cat_id = m.getId();
cat_catkey = m.getKey();
cat_index_order = m.getIndexOrder();
c.setCatkey(m.getKey());
c.setColor(m.getColor());
c.setIcon(m.getIcon());
c.setIcon_white(m.getIconWhite());
c.setId(m.getId());
c.setName(m.getName());
/*GetServiceDataIdByCategoryIdRequest request1 = new GetServiceDataIdByCategoryIdRequest();
request1.setId(cat_id);
GetServiceDataIdByCategoryIdResponse response1 = iCruxPanelClientService.getServiceDataIdByCategoryId(request1);*/
/*ArrayList<ServiceMaster> service = new ArrayList<ServiceMaster>();
for (int i=0;i<2;i++)
{
ServiceMaster serv = new ServiceMaster();
serv.setCcNumber("12344444");
serv.setCta("123");
serv.setIcon("sdgf");
serv.setId(1);
serv.setKey("dsgdfg");
serv.setName("name");
serv.setOrderSuccessMessage("fgjdoi");
serviceMaster.add(serv);
}*/
c.setPosmNumber(cat_id);
return c;
}
@RequestMapping(value = "/printPosmDetails", method = RequestMethod.GET, produces = "application/json")
public
@ResponseBody
ArrayList<Posm> printPosmDetails(HttpServletRequest request) {
ArrayList<Posm> messages = new ArrayList<Posm>();
String catid = request.getParameter("catId");
System.out.println("\n\n\n\n" + catid + "\n\n\n\n\n");
Posm posm = new Posm();
for (int i = 0; i <= 1; i++) {
posm.setName("serviceMaster.get(i).getName()");
posm.setMessage("serviceMaster.get(i).getOrderSuccessMessage()");
System.out.println("\n\n\n\nsakjhdkashdkhasd" + catid + "\n\n\n\n\n");
messages.add(posm);
}
System.out.println(serviceMaster.size());
return messages;
}
@RequestMapping(value = "/updateCategory", method = RequestMethod.POST)
public String update(HttpServletRequest request) {
iCruxPanelClientService.setCruxWebServiceBaseURL(cruxClientUrl);
UpdateCategoryRequest updateCategoryRequest = new UpdateCategoryRequest();
CategoryModel categoryModel = new CategoryModel();
categoryModel.setColor(request.getParameter("color"));
categoryModel.setIcon(request.getParameter("icon"));
categoryModel.setIconWhite(request.getParameter("iconWhite"));
categoryModel.setName(request.getParameter("name"));
categoryModel.setId(cat_id);
categoryModel.setKey(cat_catkey);
categoryModel.setIndexOrder(cat_index_order);
updateCategoryRequest.setCategory(categoryModel);
System.out.println(request.getParameter("posmi1"));
System.out.println(request.getParameter("posmi2"));
System.out.println(categoryModel.getColor() + " " + categoryModel.getId() + " " + categoryModel.getKey() + " " + categoryModel.getIndexOrder());
iCruxPanelClientService.updateCategory(updateCategoryRequest);
return "redirect:editCategories";
}
}
在API /printPosmDetails
我正在尝试并访问Arraylist然后它抛出并出错但我能够访问其他全局变量,如cat_id和类似。为什么会这样?