SpringMVC遇到的一些小问题

来源:互联网 发布:centos安装yum 编辑:程序博客网 时间:2024/06/05 19:15
1、空指针:
@Autowiredprivate DepartmentDao departmentDao;
出现该问题主要是忘记添加了@Autowired注解  导致departmentDao未注入到employeeDao中  从而出现departmentDao中的getDepartment(id)方法不能用
2、重定向的时候404:
主要问题出现在
return "redirect: /empList";
当时重定向的是到一个一个页面因此无法找到根路径的redirect: List.jsp"; 后来发现后  重定向到
@RequestMapping("/empList")public String list(Map<String,Object> map){map.put("employees", employeeDao.getAll());System.out.println(employeeDao.getAll());return "list";}

中的/empList 问题就解决了 如果重定向到页面的话直接写页面的名去掉.jsp就可以了 但是如果重定向的路径不是jsp那就需要找到对应方法的requestMapping中的路径再进行重定向

原创粉丝点击