Obtained 'foo' query parameter value 'bar'
http://localhost:8080/spring_mvc_test/data/param?foo=test
@RequestMapping(value="param")
public @ResponseBody String withParam(@RequestParam String foo) {
String message = "Obtained 'foo' query parameter value '" + foo + "'";
return message;
}
结果:Obtained 'foo' query parameter value 'test'
Obtain parameter group Param1:foo, Param2:bar, Params:baz
http://localhost:8080/spring_mvc_test/data/group?param1=foo¶m2=bar¶m3=baz
@RequestMapping(value="group")
public @ResponseBody String withParamGroup(JavaBean bean) {
String message = "Obtained parameter group: "
+ bean.getParam1() + "," + bean.getParam2() + "," + bean.getParam3();
return message;
}
JavaBean:
private String param1;
private String param2;
private String param3;
Obtain 'var' path variable value 'foo'
http://localhost:8080/spring_mvc_test/data/path/foo
@RequestMapping(value="path/{var}")
public @ResponseBody String withPathVariable(@PathVariable String var) {
String message = "path variable:" + var;
return message;
}
Obtained 'Accept'header 'text/plain, */*'
http://localhost:8080/spring_mvc_test/data/header
@RequestMapping(value="header")
public @ResponseBody String withHeader(@RequestHeader String Accept) {
String message = "Obtained 'Accept' header '" + Accept + "'";
return message;
}
Obtained 'Accept' header 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*'
posted request body 'foo'
<form action="http://localhost:8080/spring_mvc_test/data/body" method="post">
<input type="text" name="aaa"/>
<input type="submit" value="提交" />
</form>
@RequestMapping(value="body", method=RequestMethod.POST)
public @ResponseBody String withBody(@RequestBody String body) {
String message = "body:" + body;
return message;
}
结果:body:aaa=aaasdfasf
Request Body and Headers
@RequestMapping(value="entity", method=RequestMethod.POST)
public @ResponseBody String withEntity(HttpEntity<String> entity) {
String message = "Posted request body '" + entity.getBody() "'; header = " + entity.getHeaders();
return message;
}
read a form
<form action="http://localhost:8080/spring_mvc_test/data/form" method="post">
<input type="text" id="aaa" name="aaa"/>
<input type="text" id="bbb" name="bbb"/>
<input type="submit" value="提交" />
</form>
@RequestMapping(value="form", method=RequestMethod.POST)
public @ResponseBody String withEntity(@RequestBody MultiValueMap<String, String> form) {
String message = "read from map" + form;
return message;
}
read from map{aaa=[qqq], bbb=[www]}
write a form
http://localhost:8080/spring_mvc_test/data/form
@RequestMapping(value="/form", method=RequestMethod.GET)
public @ResponseBody MultiValueMap<String, String> writeForm() {
MultiValueMap<String, String> map = new LinkedMultiValueMap<String , String>();
map.add("foo", "bar");
map.add("fruit", "apple");
return map;
}
分享到:
相关推荐
Obtaining Request Data Generating Responses Message Converters Rendering Views Type Conversion Validation Forms AngularJS MongoDB 跑步: 从命令行使用 Maven: $ mvn tomcat7:run [-Dmaven.tomcat.port=]...
介绍Spring MVC应用程序示例。 只需以mvn clean tomcat7:run身份运行嵌入式Tomcat服务器,即可在上测试该应用程序。执照该示例应用程序及其关联的源代码全部按照以下许可条款提供。 Copyright (C) 2015Permission is...
Organizations invest incredible amounts of time and money obtaining and then storing big data in data stores called data lakes. But how many of these organizations can actually get the data back out ...
this script was built for curve data obtaining
This book examines how to go about obtaining, processing, storing, managing and analyzing data using the Python programming language. You will use Python and other open source tools to wrangle data ...
This book examines how to go about obtaining, processing, storing, managing and analyzing data using the Python programming language. You will use Python and other open source tools to wrangle data ...
Examine methods for obtaining, cleaning, and arranging data into its purest form Understand the matrix structure that your data should take Learn basic concepts for testing the origin and validity of ...
The authors recommend web scraping as a powerful tool for any data scientist’s arsenal, as many data science projects start by obtaining an appropriate data set. Starting with a brief overview on ...
1-1-Obtaining Data Motivation (5-38) .mp4 1 - 2 - Raw and Processed Data (7-07).mp4 1 - 3 - Components of Tidy Data (9-25).mp4 1 - 4 - Downloading Files (7-09).mp4 1 - 5 - Reading Local Files (4-55)....
Obtaining Absolute Encoder Position on a TMS320C240.pdf
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
C#C#A Method for Obtaining Digital Signatures and Public-Key Cryptosystems A Method for Obtaining Digital Signatures and Public-Key Cryptosystems A Method for Obtaining Digital Signatures and Public-...
domain user password obtaining
The authors recommend web scraping as a powerful tool for any data scientist’s arsenal, as many data science projects start by obtaining an appropriate data set. Starting with a brief overview on ...
有时候当你的程序崩溃时能获得堆栈轨迹是很有用处的。很多人认为当程序崩溃时用C/C++难以获知程序在哪出现了错误。在很大程度上,C/C++的确难以做到,但是调试器却能做到这一点。下文给出的程序可以做到不用调试器却...
In addition, data structures are essential building blocks in obtaining efficient algorithms. This course will cover major results and current directions of research in data structures.
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
Copyright (C) 2014Permission is hereby granted, free of charge, to any person obtaining a copy ofthis software and associated documentation files (the "Software"), to deal in theSoftware without ...
* __data__ rewritten to support "parser profiles" which allow shallow data requests to be highly optimized using new parsers. * __sig__ now allow arbitrary number of arguments to any method...
7.12. MVC 异常 7.12.1. 介绍 7.12.2. 如何处理异常? 7.12.3. 可能遭遇的MVC异常 7.13. 从以前的版本移植 7.13.1. 从 1.0.x 到 1.5.0 或更新的版本的移植 7.13.2. 从 0.9.3 到 1.0.0RC1 或更新的版本的移植 ...