【发布时间】:2015-01-20 10:30:46
【问题描述】:
我使用 spring 做了一个简单的程序。当我没有使用类级别 RequestMapping 时,我得到了方法级别 RequestMapping 的答案。但我想同时使用类级别和方法级别的RequestMapping。
这是我的控制器代码
package com.birthid;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/classLevel")
public class Controaller1
{
@RequestMapping("/spring")
public ModelAndView display(@RequestParam("name") String name)
{
ModelAndView model=new ModelAndView("view");
model.addObject("msg", name);
return model;
}
}
html代码
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Hello App Engine</title>
</head>
<body>
<h1>valith web application!</h1>
<form action="/classLevel" method="get">
name:<input type="text" name="name"/><br>
<input type="submit" value="clik me"/>
</form>
</body>
</html>
当我在地址栏中提供此网址时。我得到了准确的输出。 http:localhost:8888/classLevel/spring?name=john
但是当我按下我在 html 页面中设计的按钮时,就会出错。
【问题讨论】:
-
嗯,你的表单动作是/classLevel,你的方法映射到/classLevel/spring,所以这很符合预期,不是吗?
-
我不知道如何先映射。
标签: spring spring-mvc