【发布时间】:2021-03-09 07:13:47
【问题描述】:
我的主页包含城市、国家、州、用户详细信息等功能,以及一些代表用户数据分析的饼图和图表。我是 spring mvc 的新手,我很困惑是否应该加载数据一次打开主页,或者我应该有 onclick 调用,它会调用我的控制器并加载数据。
Example:
MyController Class
public class HomeController {
@Autowired
private EngagaementService engagaementService;
@Autowired
private EmployeeService employeeService;
@Autowired
private CgOfficeDetailsService cgOfficeDetailsService;
@RequestMapping("/")
public ModelAndView handleRequest() {
List<EmployeeInfo> listEmployees = employeeService.listEmployeeInfos();
ModelAndView model = new ModelAndView("index");
model.addObject("emp", listEmployees);
model.addObject("empCount", listEmployees.size());
return model;
}
@GetMapping("/getCity")
public ModelAndView getBU(HttpServletRequest request) {
String country = "India";
List<String> buList = employeeService.getCityName(country);
ModelAndView model = new ModelAndView("index");
model.addObject("buList", buList);
return model;
}
@GetMapping("/getState")
public ModelAndView getState(HttpServletRequest request) {
String country = "UP";
List<String> buList = employeeService.getState(country);
ModelAndView model = new ModelAndView("index");
model.addObject("buList", buList);
return model;
}
@GetMapping("/getUsers")
public ModelAndView getUsers(HttpServletRequest request) {
String country = "UP";
List<String> buList = employeeService.getState(country);
ModelAndView model = new ModelAndView("index");
model.addObject("buList", buList);
return model;
}
【问题讨论】:
标签: ajax spring jsp model-view-controller controller