老师,我不知道到底哪里有问题这个
用test就可以显示出来
add就报404
package com.imooc.controller;
import com.imooc.dao.TeacherDao;
import com.imooc.entity.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class TeacherController {
@Autowired
private TeacherDao teacherDao;
@RequestMapping("/test")
@ResponseBody
public String test(int id) {
return "id:" + id;
}
@PostMapping(value = "/add")
public String add(Teacher teacher) {
teacherDao.add(teacher);
return "redirect:/selectAll";
}
@GetMapping(value = "/selectById/{id}")
public ModelAndView selectById(@PathVariable(value = "id") int id) {
Teacher teacher = teacherDao.selectById(id);
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("teacher", teacher);
modelAndView.setViewName("update");
return modelAndView;
}
@PutMapping(value = "/update")
public String update(Teacher teacher) {
teacherDao.update(teacher);
return "redirect:/selectAll";
}
@DeleteMapping(value = "/delete/{id}")
public String delete(@PathVariable(value = "id")int id){
teacherDao.delete(id);
return "redirect:/selectAll";
}
@GetMapping("/selectAll")
public ModelAndView selectAll(){
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("teachers",teacherDao.selectAll());
modelAndView.setViewName("index");
return modelAndView;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 配置自动扫描 -->
<context:component-scan base-package="com.imooc"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
报的错误
org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/SpringMVCRestful_war_exploded/add] in DispatcherServlet with name 'springmvc'
请老师帮我解决这个问题
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星