spring rest 增删改查(put\delete\post\get)简单示例详细讲解
来源:互联网 发布:黑客远控软件 编辑:程序博客网 时间:2024/06/02 03:59
spring rest 增删改查(put\delete\post\get)简单示例详细讲解
(1)类HelloController
package com.demo.java;
import java.util.List;
import javax.websocket.server.PathParam;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value="/hello")
public class HelloController {
/**
* 测试链接:http://localhost:8080/springmvc_demo/hello/gettest1?name=xiaokeai
* 测试结果:gettest1 was invoked.hello xiaokeai
*/
@RequestMapping(value="/gettest1",method=RequestMethod.GET)
public String gettest1(@PathParam("name") String name){
return "gettest1 was invoked.hello " + name;
}
/**
*测试链接:http://localhost:8080/springmvc_demo/hello/gettest2/user1/25
*测试结果:gettest2 was invoked.hello user1,age 25
*/
@RequestMapping(value="/gettest2/{name}/{age}",method=RequestMethod.GET)
public String gettest2(@PathVariable String name,@PathVariable int age){
return "gettest2 was invoked.hello " + name + ",age " + age;
}
/**
* 测试链接:http://localhost:8080/springmvc_demo/hello/posttest1
* 测试header:Content-Type=application/json
* 测试body:{"id":"111","name":"xiaokeai","age":26}
* 控制台输出:update.new age is 29.
* 测试结果:{"id":"111","name":"xiaokeai","age":29}
*/
@RequestMapping(value = "/posttest1", method = RequestMethod.POST,
consumes = "application/json")
@ResponseBody
public TeacherVO posttest1(@RequestBody TeacherVO t) {
System.out.println("update.new age is 29.") ;
t.setAge(29) ;
return t;
}
/**
* 测试链接:http://localhost:8080/springmvc_demo/hello/puttest1
* 测试header:Content-Type=application/json
* 测试body:{"id":"111","name":"xiaokeai","age":26}
* 控制台输出:insert.t:Teacher [id=111, name=xiaokeai, age=26]
* 测试结果:1
*/
@RequestMapping(value = "/puttest1", method = RequestMethod.PUT)
public int puttest1(@RequestBody TeacherVO t){
System.out.println("insert.t:" + t);
return 1 ;
}
/**
* 测试链接:http://localhost:8080/springmvc_demo/hello/deletetest1/111
* 控制台输出:delete.id:111
* 测试结果:1
*/
@RequestMapping(value = "/deletetest1/{id}", method = RequestMethod.DELETE)
public int deletetest1(@PathVariable String id) {
System.out.println("delete.id:" + id) ;
return 1 ;
}
/**
* 测试链接:http://localhost:8080/springmvc_demo/hello/deletetest2
* 测试header:Content-Type=application/json
* 测试body:["1","2","3"]
* 控制台输出:delete.ids:[1, 2, 3]
* 测试结果:1
*/
@RequestMapping(value = "/deletetest2", method = RequestMethod.DELETE)
@ResponseBody
public int deletetest1(@RequestBody List<String> ids) {
System.out.println("delete.ids:" + ids) ;
return 1 ;
}
}
(2)类TeacherVO
package com.demo.java;
public class TeacherVO {
private String id ;
private String name ;
private int age ;
public TeacherVO(){
}
public TeacherVO(String id, String name, int age) {
super();
this.id = id;
this.name = name;
this.age = age;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Teacher [id=" + id + ", name=" + name + ", age=" + age + "]";
}
}
阅读全文
0 0
- spring rest 增删改查(put\delete\post\get)简单示例详细讲解
- SpringMVC rest风格(Post增 Delete删 Put改 get查)
- SpringMVC rest风格(Post增 Delete删 Put改 get查)
- get,post ,put,delete 与查,改,增,删
- SpringMVC 实现(Post增 Delete删 Put改 get查)
- REST统一接口 GET PUT DELETE POST
- get、post、put、delete的简单理解
- GET/POST/PUT/DELETE
- get/post/put/delete
- Rest模式get,put,post,delete含义与区别(转)
- Rest模式get,put,post,delete含义与区别
- Rest模式get,put,post,delete含义与区别
- Rest模式get,put,post,delete含义与区别(转)
- springmvc实现REST中的GET、POST、PUT和DELETE
- Rest模式get,put,post,delete含义与区别(转)
- Rest模式下get,put,post,delete的区别
- Rest模式get,put,post,delete含义与区别
- springmvc实现REST中的GET、POST、PUT和DELETE
- 计时器应用
- Python 封装,继承,多态
- Java集合框架List入门学习
- openstack 原版部署问题解决合集(待完善)
- python DEAP学习4(遗传算法)函数使用
- spring rest 增删改查(put\delete\post\get)简单示例详细讲解
- C#委托的介绍(delegate、Action、Func、predicate)
- 11 程序员的发展方向和薪水
- ARP协议与RARP协议
- Ubuntu设置Static IP的方法Ifconfig网络配置工具详解
- 高级CSS filters
- 虚拟机下 linux 连接网络并设置固定ip
- MVP模型复杂视图的思考
- 从零开始的Spring Boot (一)