controller

  package com.example.demo.controller;

  import java.util.HashMap;

  import java.util.Map;

  import org.apache.catalina.servlet4preview.http.HttpServletRequest;

  import org.springframework.web.bind.annotation.GetMapping;

  import org.springframework.web.bind.annotation.PathVariable;

  import org.springframework.web.bind.annotation.RequestBody;

  import org.springframework.web.bind.annotation.RequestHeader;

  import org.springframework.web.bind.annotation.RequestMapping;

  import org.springframework.web.bind.annotation.RequestMethod;

  import org.springframework.web.bind.annotation.RequestParam;

  import org.springframework.web.bind.annotation.RestController;

  import com.example.demo.domain.User;

  @RestController

  @RequestMapping("/get")

  public class GetController {

  Map result = new HashMap();

  /**

  * 测试GET请求1

  * @return

  */

  @RequestMapping(path="/test1", method=RequestMethod.GET)

  public String test1() {

  return "test1...";

  }

  /**

  * 测试GET请求2(使用GetMapping简写)

  * @return

  */

  @GetMapping("/test2")

  public String test2(){

  return "test2...";

  }

  /**

  * 测试GET请求参数传递及默认值

  * @return

  */

  @GetMapping("/test3")

  public Object test3(@RequestParam(defaultValue="0",name="a") int a, int b){

  result.clear();

  result.put("a", a);

  result.put("b", b);

  return result;

  }

  /**

  * 测试restful协议,从路径中获取字段

  * @param cityId

  * @param userId

  * @return

  */

  @GetMapping("/{city_id}/{user_id}")

  public Object findUser(@PathVariable("city_id") String cityId,

  @PathVariable("user_id") String userId) {

  result.clear();

  result.put("cityId", cityId);

  result.put("userId", userId);

  return result;

  }

  /**

  * Bean对象传参

  * 注意:1、要指定http请求头content-type为application/json

  * 2、使用body传输数据

  * @param user

  * @return。

  */

  @GetMapping("/saveuser")

  public Object savaUser(@RequestBody User user){

  result.clear();

  result.put("user", user);

  return result;

  }

  /**

  * 获取http请求头部信息

  * @param accessToken

  * @param contentType

  * @return

  */

  @GetMapping("/headerinfo")

  public Object headerinfo(@RequestHeader("access_token") String accessToken,

  @RequestHeader("Content-Type") String contentType) {

  result.clear();

  result.put("access_token", accessToken);

  result.put("content_type", contentType);

  return result;

  }

  /**

  * 获取request对象传递的参数

  * @param request

  * @return

  */

  @GetMapping("/requestparams")

  public Object requestparams(HttpServletRequest request){

  result.clear();

  result.put("param1", request.getParameter("param1"));

  return result;

  }

  }

  User实体类

  package com.example.demo.domain;

  import java.util.Date;

  import com.fasterxml.jackson.annotation.JsonFormat;

  import com.fasterxml.jackson.annotation.JsonIgnore;

  import com.fasterxml.jackson.annotation.JsonInclude;

  import com.fasterxml.jackson.annotation.JsonInclude.Include;

  import com.fasterxml.jackson.annotation.JsonProperty;

  public class User {

  @JsonProperty("name")

  private String username;

  @JsonIgnore

  private String userid;

  @JsonIgnore

  private String password;

  @JsonInclude(Include.NON_NULL)

  private Integer age;

  @JsonInclude(Include.NON_NULL)

  @JsonFormat(pattern="yyyy-MM-dd hh:mm:ss", locale="zh", timezone="GMT+8")

  private Date createTime;

  public User() {

  super();

  }郑州妇科医院哪家好 http://mobile.chfk120.com/

  public User(String username, String userid, String password, Integer age, Date createTime) {

  super();

  this.username = username;

  this.userid = userid;

  this.password = password;

  this.age = age;

  this.createTime = createTime;

  }

  public String getUsername() {

  return username;

  }

  public void setUsername(String username) {

  this.username = username;

  }

  public String getUserid() {

  return userid;

  }

  public void setUserid(String userid) {

  this.userid = userid;

  }

  public String getPassword() {

  return password;

  }

  public void setPassword(String password) {

  this.password = password;

  }

  public Integer getAge() {

  return age;

  }

  public void setAge(Integer age) {

  this.age = age;

  }

  public Date getCreateTime() {

  return createTime;

  }

  public void setCreateTime(Date createTime) {

  this.createTime = createTime;

  }

  }

SpringBoot学习笔记:http接口请求的更多相关文章

  1. SpringBoot学习笔记:Swagger实现文档管理

    SpringBoot学习笔记:Swagger实现文档管理 Swagger Swagger是一个规范且完整的框架,用于生成.描述.调用和可视化RESTful风格的Web服务.Swagger的目标是对RE ...

  2. SpringBoot学习笔记:自定义拦截器

    SpringBoot学习笔记:自定义拦截器 快速开始 拦截器类似于过滤器,但是拦截器提供更精细的的控制能力,它可以在一个请求过程中的两个节点进行拦截: 在请求发送到Controller之前 在响应发送 ...

  3. SpringBoot学习笔记

    SpringBoot个人感觉比SpringMVC还要好用的一个框架,很多注解配置可以非常灵活的在代码中运用起来: springBoot学习笔记: .一.aop: 新建一个类HttpAspect,类上添 ...

  4. SpringBoot学习笔记(3):静态资源处理

    SpringBoot学习笔记(3):静态资源处理 在web开发中,静态资源的访问是必不可少的,如:Html.图片.js.css 等资源的访问. Spring Boot 对静态资源访问提供了很好的支持, ...

  5. SpringBoot学习笔记(2):引入Spring Security

    SpringBoot学习笔记(2):用Spring Security来保护你的应用 快速开始 本指南将引导您完成使用受Spring Security保护的资源创建简单Web应用程序的过程. 参考资料: ...

  6. SpringBoot学习笔记(4):添加自定义的过滤器

    SpringBoot:学习笔记(4)——添加自定义的过滤器 引入自定义过滤器 SpringBoot提供的前端控制器无法满足我们产品的需求时,我们需要添加自定义的过滤器. SpringBoot添加过滤器 ...

  7. SpringBoot学习笔记(10):使用MongoDB来访问数据

    SpringBoot学习笔记(10):使用MongoDB来访问数据 快速开始 本指南将引导您完成使用Spring Data MongoDB构建应用程序的过程,该应用程序将数据存储在MongoDB(基于 ...

  8. SpringBoot学习笔记:动态数据源切换

    SpringBoot学习笔记:动态数据源切换 数据源 Java的javax.sql.DataSource接口提供了一种处理数据库连接的标准方法.通常,DataSource使用URL和一些凭据来建立数据 ...

  9. springboot学习笔记:9.springboot+mybatis+通用mapper+多数据源

    本文承接上一篇文章:springboot学习笔记:8. springboot+druid+mysql+mybatis+通用mapper+pagehelper+mybatis-generator+fre ...

  10. openresty 学习笔记二:获取请求数据

    openresty 学习笔记二:获取请求数据 openresty 获取POST或者GET的请求参数.这个是要用openresty 做接口必须要做的事情.这里分几种类型:GET,POST(urlenco ...

随机推荐

  1. 石欣钰-201871010117 《面向对象程序设计(java)》第六、七周学习总结

    项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业要求在哪里 https://www.cnblogs.com/nwnu-daizh/p/ ...

  2. Android开发环境搭建(个人环境非通用)

    1.安装andorid studio 2.连接模拟器,AMD处理器为无法使用AVD manager ,所以连接第三方的Genymotion模拟器,设置中安装Genymotion插件,重启即可(Geny ...

  3. 7 Exciting Uses of Machine Learning in FinTech

    https://rubygarage.org/blog/machine-learning-in-fintech Machine learning (ML) has moved from the per ...

  4. Linux性能优化实战学习笔记:第四讲

    一.怎么查看系统上下文切换情况 通过前面学习我么你知道,过多的上下文切换,会把CPU时间消耗在寄存器.内核栈以及虚拟内存等数据的保存和回复上,缩短进程真正运行的时间,成了系统性能大幅下降的一个元凶 既 ...

  5. [LeetCode] 381. Insert Delete GetRandom O(1) - Duplicates allowed 常数时间内插入删除和获得随机数 - 允许重复

    Design a data structure that supports all following operations in average O(1) time. Note: Duplicate ...

  6. 阿里Sentinel控制台源码修改-对接Apollo规则持久化

    改造背景 前面我们讲解了如何对接Apollo来持久化限流的规则,对接后可以直接通过Apollo的后台进行规则的修改,推送到各个客户端实时生效. 但还有一个问题就是Sentinel控制台没有对接Apol ...

  7. 如何让position fixed不再基于浏览器窗口定位

    position:fixed默认是相对浏览器定位的. 就是将某个元素固定在浏览器的某个确定的位置,不随滚动条的移动而变化: MDN对position: fixed有一个注释: 当元素祖先的 trans ...

  8. .NetCore 入门篇:理解

    (良心转载)原文地址:https://ken.io/note/dotnet-core-qucikstart-preface 一..NET Core的诞生 聊 .NET Core,就不得不说他的爸爸 . ...

  9. LeetCode 167:两数之和 II - 输入有序数组 Two Sum II - Input array is sorted

    公众号: 爱写bug(ID:icodebugs) 给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数. 函数应该返回这两个下标值 index1 和 index2,其中 index ...

  10. FutureTask源码

    FutureTask可用于异步获取执行结果或取消执行任务的场景.通过传入Runnable或者Callable的任务给FutureTask,直接调用其run方法或者放入线程池执行,之后可以在外部通过Fu ...