Recently in the use of Postman Test Postman Interface, for the SPRINGMVC value this piece, tested several common ways, summed up. The use of the Postman tool has also been added to the understanding. Postman testing is great, with tools, testing interfaces, and inefficient.
One, single parameter passing
[Email protected] Annotations
[Java]View PlainCopyPrint?
- <span style= "font-family: ' kaiti_gb2312 '; font-size:18px;" > /**
- * Test single parameter @requestbody
- */
- @CrossOrigin
- @RequestMapping (value = {"/inserttestparamsrequest"}, method = Requestmethod.get)
- @ResponseBody
- Public void inserttestparamsrequest (@RequestBody String name, @ Requestbody String age) {
- System.out.println ("name=====" + name);
- System.out.println ("age=====" + age);
- }
- </span>
/** * Test a single parameter @requestbody * /@CrossOrigin @RequestMapping (value = {"/inserttestparamsrequest"}, method = Requestmethod.get) @ResponseBody public void Inserttestparamsrequest (@RequestBody String name, @ Requestbody String age) { System.out.println ("name=====" + name); System.out.println ("age=====" + age); }
Test Request Path
[Email protected]
Commonly used to handle a simple type of binding, a string obtained through Request.getparameter () can be converted directly to a simple type of case (;
The note has two properties: value, required; value is used to specify the ID name to pass in the value, required is used to indicate whether the parameter must be bound;
[Java]View PlainCopyPrint?
- <span style= "font-family: ' kaiti_gb2312 '; font-size:18px;" > /**
- * Test single parameter @requestparam
- */
- @CrossOrigin
- @RequestMapping (value = {"/inserttestparams"}, method = Requestmethod.get)
- @ResponseBody
- Public void inserttestparams (httpservletrequest request, @RequestParam String name, @RequestParam string age) {
- System.out.println ("name=====" + name);
- System.out.println ("age=====" + age);
- }</span>
/** * Test single parameter @requestparam * /@CrossOrigin @RequestMapping (value = {"/inserttestparams"}, Method = Requestmethod.get) @ResponseBody public void Inserttestparams (HttpServletRequest request, @RequestParam String name, @RequestParam string age) { System.out.println ("name=====" + name); System.out.println ("age=====" + age); }
Request Path:
[Email protected] Annotations
The path is resultful style and the parameter is used as the request path.
When using the @requestmapping URI template style mapping, which is Url/{paramid}, the Paramid can bind the value passed to the method by @Pathvariable annotations.
[Java]View PlainCopyPrint?
- <span style= "font-family: ' kaiti_gb2312 '; font-size:18px;" > /**
- * Test single parameter @pathvariable
- */
- @CrossOrigin
- @RequestMapping (value = {"/inserttest/{name}/{age}"}, method = Requestmethod.get)
- @ResponseBody
- Public void inserttestpathveriable (httpservletrequest request, @PathVariable( "name") string name, @PathVariable string age) {
- System.out.println ("name=====" + name);
- System.out.println ("age=====" + age);
- }</span>
/** * Test single parameter @pathvariable * /@CrossOrigin @RequestMapping (value = {"/inserttest/{name}/{age}"}, method = Requestmethod.get) @ResponseBody public void inserttestpathveriable (HttpServletRequest request, @ Pathvariable ("name") string name, @PathVariable string age) { System.out.println ("name=====" + name); System.out.println ("age=====" + age); }
The above code binds the value of the variable name in the URI template and the value of age to the parameter of the method. If the variable names in the method parameter names and URI template that need to be bound are inconsistent, you need to specify the name in the URI template in @pathvariable ("name").
Second, pass the Pojo object
[Email protected] Annotations
[Java]View PlainCopyPrint?
- <span style= "font-family: ' kaiti_gb2312 '; font-size:18px;" > / * Test Add entity * /
- @CrossOrigin
- @RequestMapping (value = {"/insertentitytest"}, method = Requestmethod.post)
- @ResponseBody
- Public void insertentitytest (@RequestBody curriculumscheduleentity curriculumscheduleentity) {
- System.out.println ("name=====" + curriculumscheduleentity.getclassid ());
- System.out.println ("age=====" + curriculumscheduleentity.getteachclassid ());
- }</span>
/* Test Add Entity * /@CrossOrigin @RequestMapping (value = {"/insertentitytest"}, method = Requestmethod.post) @ Responsebody public void Insertentitytest (@RequestBody curriculumscheduleentity curriculumscheduleentity) { System.out.println ("name=====" + curriculumscheduleentity.getclassid ()); System.out.println ("age=====" + curriculumscheduleentity.getteachclassid ()); }
Postman Test with JSON format
2. Write entities directly
[Java]View PlainCopyPrint?
- <span style= "font-family: ' kaiti_gb2312 '; font-size:18px;" > / * Test Add entity * /
- @CrossOrigin
- @RequestMapping (value = {"/inserttest"}, method = Requestmethod.post)
- @ResponseBody
- Public void inserttest (curriculumscheduleentity curriculumscheduleentity) {
- System.out.println ("name=====" + curriculumscheduleentity.getclassid ());
- System.out.println ("age=====" + curriculumscheduleentity.getweekid ());
- }</span>
/* Test Add Entity * /@CrossOrigin @RequestMapping (value = {"/inserttest"}, method = Requestmethod.post) @ Responsebody public void Inserttest (curriculumscheduleentity curriculumscheduleentity) { System.out.println ("name=====" + curriculumscheduleentity.getclassid ()); System.out.println ("age=====" + curriculumscheduleentity.getweekid ()); }
Form form Test
[HTML]View PlainCopyPrint?
- < span style="font-family: ' kaiti_gb2312 '; font-size:18px;" > < Div >
- < form action="/curriculumschedule/inserttest" method ="POST">
- ClassId:<input name="classId">< br >
- Teachclassid:<input name="weekid"> <br >
- < input type= " submit" value="commit">
- </ form >
- </ Div > </ span >
<div> <form action= "/curriculumschedule/inserttest" method= "POST" > classId: <input Name= "ClassId" ><br> teachclassid:<input name= "Weekid" ><br> <input type= " Submit "value=" > </form></div>
Postman Test format
Iii. postman Test List type parameters
Take list<string> as an example, test the bulk Delete method, the parameter is list<string>. Write this actually no technology, but at noon in the Test list interface, with postman test, format consistent write wrong, do not know how to test with postman. So it took a little time to record and think about the process of the tool's execution.
Controller method
3. Reference connection
Http://www.cnblogs.com/sandyliu1999/p/4802706.html
"SPRINGMVC" several ways to pass the value &&postman interface test