springmvc讲的就是两件事:浏览器向服务器发送请求,服务器向浏览器响应数据
浏览器向服务器提交请求
1.当你不指定请求方式是get还是post的时候,默认就是采用Get方式提交请求
你在浏览器地址栏中输入alpha/http就可以访问这个方法http
可以看出:请求默认是get请求(而不是post请求)
@RequestMapping("/alpha")
public class Controller
{
@RequestMapping("/http")
public void http(HttpServletRequest request, HttpServletResponse response) throws IOException
{
System.out.println(request.getMethod());//请求方式 GET
System.out.println(request.getServletPath());//请求路径 /alpha/http
Enumeration<String> enumeration=request.getHeaderNames();//把请求的消息头打印出来host: localhost:8080....
while(enumeration.hasMoreElements())//把请求头的每一行name:value取出来
{
String name=enumeration.nextElement();
String value=request.getHeader(name);
System.out.println(name+": "+value);
}
System.out.println(request.getParameter("code"));
//请求传入的参数,比如你输alpha/http?code=123,表明传入的参数就是123,那code就等于123,没有参数就是nul
}
}
2.指定以get方式提交请求
@RequestMapping("/students",method= RequestMethod.GET)
@ResponseBody //表示返回的是一个字符串
//第几页,1页展示几行数据
public String getStudents(int current, int limit)
{
System.o