标注RequestMapping后无法通过 http://localhost:8082/Test/FormAdd 地址访问到 提示404错误 只能通过 http://localhost:8082/FormAdd,问下怎么配置
代码如下 :
package com.springapp.mvc;
import com.data.dataaccess.HibernateHelper;
import com.data.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.management.Attribute;
@Controller
@RequestMapping(name="/Test")
public class TestController {
@RequestMapping(value = "/TestAttr",method = {RequestMethod.GET,RequestMethod.HEAD})
public String TestAttr(ModelMap model) {
Class item = MyClass.class;
if(item.isAnnotationPresent(MyAttribute.class)){
model.addAttribute("message", "has annotation myattribute");
MyAttribute itemAttr =(MyAttribute) item.getAnnotation(MyAttribute.class);
model.addAttribute("value", itemAttr.value());
}
return "/test/testAttr";
}
@RequestMapping(value = "/FormAdd",method = {RequestMethod.GET})
public String TestFormAdd(ModelMap model) {
return "/test/addStudent";
}
@RequestMapping(value = "/FormAdd",method = {RequestMethod.POST})
public String TestFormAdd(ModelMap model,Student student) {
try {
org.hibernate.Session session = HibernateHelper.GetFactory().openSession();
session.beginTransaction();
session.save(student);
session.getTransaction().commit();
model.addAttribute("statu","success");
}
catch (Exception e){
model.addAttribute("statu","failed"+e.getMessage());
}
return "/test/addStudent";
}
}
xml配置:
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
原
改