页面跳转为404
我复制粘贴源代码,输入http://localhost:8080/sm/department/list.jsp,启动服务器后,跳转成404
package com.imooc.sm.dao; import com.imooc.sm.entity.Department; import org.springframework.stereotype.Repository; import java.util.List; @Repository("departmentDao") public interface DepartmentDao { void insert(Department department); void delete(Integer id); void update(Department department); Department selectById(Integer id); List<Department> selectAll(); } package com.imooc.sm.service; import com.imooc.sm.entity.Department; import java.util.List; public interface DepartmentService { void add(Department department); void remove(Integer id); void edit(Department department); Department get(Integer id); List<Department> getAll(); }
package com.imooc.sm.service.impl;
import com.imooc.sm.dao.DepartmentDao;
import com.imooc.sm.entity.Department;
import com.imooc.sm.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("departmentService")
public class DepartmentServiceImpl implements DepartmentService {
@Qualifier("departmentDao")
@Autowired
private DepartmentDao departmentDao;
public void add(Department department) {
departmentDao.insert(department);
}
public void remove(Integer id) {
departmentDao.delete(id);
}
public void edit(Department department) {
departmentDao.update(department);
}
public Department get(Integer id) {
return departmentDao.selectById(id);
}
public List<Department> getAll() {
return departmentDao.selectAll();
}
}
package com.imooc.sm.controller;
import com.imooc.sm.entity.Department;
import com.imooc.sm.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@Controller("departmentControllter")
public class DepartmentControllter {
@Autowired
private DepartmentService departmentService;
public void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Department> list = departmentService.getAll();
request.setAttribute("LIST",list);
request.getRequestDispatcher("../department_list.jsp").forward(request,response);
}
}
正在回答
同学你好,404错误是路径不正确,这里应该访问http://localhost:8080/sm/department/list.do,通过转发跳转到对应的页面中。另外如果如下的application context中没有写项目名,那么访问路径中不需要加项目名,如:
如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~
这是departmentDao.xml的代码 <?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.4//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.imooc.sm.dao.DepartmentDao"> <resultMap id="resultMap" type="Department"> <id property="id" column="id" javaType="Integer"/> <result property="name" column="name" javaType="String"/> <result property="address" column="address" javaType="String"/> </resultMap> <insert id="insert" parameterType="Department" useGeneratedKeys="true"> insert into department(name,address) values(#{name},#{address}) </insert> <delete id="delete" parameterType="Integer"> delete from department where id=#{id} </delete> <update id="update" parameterType="Department"> update department set name=#{name},address=#{address} where id=#{id} </update> <select id="selectById" parameterType="Integer" resultMap="resultMap"> select * from department where id=#{id} </select> <select id="selectAll" resultMap="resultMap"> select * from department </select> </mapper>
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星