写了测试类,后台可以查询到记录,但是通过访问浏览器,经过controller层时就报如上错。
public class testController {
@Test
public void test1(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
RoleService roleService = applicationContext.getBean(RoleService.class);
List<Role> list = roleService.list();
for (Role l:list
) {
System.out.println(l);
}
}
}
后台可以查询到记录:
Controller:
@RequestMapping("/role")
@Controller
public class RoleController {
@Autowired
private RoleService roleService;
@RequestMapping("/list")
public ModelAndView list(){
ModelAndView modelAndView = new ModelAndView();
List<Role> roleList = roleService.list();
//设置模型
modelAndView.addObject("roleList",roleList);
//设置视图
modelAndView.setViewName("role-list");
return modelAndView;
}
请求其他的controller可以正常访问,说明MVC是通的,但是访问这个就不行。
报错:
你可以试一下用Model model视图和@ResController搭配,返回roleList的json
有可能是懒加载的问题