我使用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>
当我在地址栏中输入此URL时,我得到了精确的输出:
http:localhost:8888/classLevel/spring?name=john
。但是当我点击HTML页面上设计的按钮时,出现了错误。