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 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)....
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
2. 句子"Living in the mountain area has its problems, ________ obtaining water is a big problem."中的"________ obtaining water"也是定语从句,修饰"problems",表示“其中获取水是个大问题”,因此用"of ...
domain user password obtaining
### 获取 C 语言程序在 SIGSEGV 时的堆栈轨迹 #### 代码实现 本文档介绍了一种在不使用调试器的情况下获取 C 或 C++ 程序崩溃时堆栈轨迹的方法。此方法尤其适用于那些希望在程序崩溃时能够追踪到错误发生位置的...
在IT领域,尤其是在嵌入式系统与数字信号处理(DSP)技术中,了解如何获取绝对编码器位置是一项关键技能。本文将深入探讨标题为“在TMS320C240上获取绝对编码器位置”的应用简报,以及其在工业自动化、机器人技术和...
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 或更新的版本的移植 ...
No prior knowledge of geospatial concepts, tools or techniques is required - The book guides you through the process of installing and using various toolkits, obtaining geospatial data for use in ...