SpringBoot打包,SpringBoot2.1.5 (9)--- GET 请求

 2023-09-26 阅读 29 评论 0

摘要:1、SpringBoot2.1.5中Get 接口请求的应用 package com.zyzx.devtool;import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController;import j

 

1、SpringBoot2.1.5中Get 接口请求的应用

package com.zyzx.devtool;import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;import java.util.HashMap;
import java.util.Map;@RestController
public class DevtoolController {private final Map<String, Object> params = new HashMap<String, Object>();/*** 功能描述: 测试restful 协议, 从路径中获取字段* @param city_id* @param user_id* @return*/@GetMapping("/{city_id}/{user_id}")public Object findObject(@PathVariable("city_id") String city_id, @PathVariable("user_id") String user_id){params.clear();params.put("city_id", city_id);params.put("user_id", user_id);return params;}
}

用postman 测试

SpringBoot打包,2 手动设置某些参数的默认值,比如页码,单页数据size等等

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;import java.util.HashMap;
import java.util.Map;@RestController
public class Devool1Controller {private final Map<String, Object> params = new HashMap<String, Object>();/*** 功能描述:测试默认值** @param page* @param size* @return*/@GetMapping(value = "/list_limit")public Object listLimit(@RequestParam(defaultValue = "0", name = "page") int page,@RequestParam(defaultValue = "10", name = "size") int size) {params.clear();params.put("page", page);params.put("size", size);return params;}
}

 

 

3.我们测试一下通过bean 对象传参

package com.zyzx.devtool;public class User {private Integer id;private String username;private Integer age;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}@Overridepublic String toString() {return "UserDao{" +"id=" + id +", username='" + username + '\'' +", age=" + age +'}';}}

java getproperty,

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/97460.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息