首页 > 其他分享 >Springboot接收请求参数示例

Springboot接收请求参数示例

时间:2022-10-04 09:55:31浏览次数:47  
标签:RequestMapping String 示例 System Springboot println 接收 public out

package com.example.demo.controller;

import com.example.demo.model.User;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/handle")
public class DemoController {
    @RequestMapping
    public String handle(@RequestParam(name = "username", required = false) String name,
                         @RequestParam String password) {
        System.out.println(name);
        System.out.println(password);
        return "finish";
    }

    @RequestMapping("/obj")
    public String handleObj(User user) {
        System.out.println(user);
        return "finish";
    }

    @RequestMapping("/json")
    public String handleJson(@RequestBody User user) {
        System.out.println(user);
        return "finish";
    }

    @RequestMapping("/url/{name}/{id}")
    public String handleUrl(@PathVariable("name") String v_name, @PathVariable Integer id) {
        System.out.println(v_name);
        System.out.println(id);
        return "finish";
    }

    @RequestMapping("/url2/{name}/{id}")
    public String handleUrl2(@PathVariable Map pathMap) {
        System.out.println(pathMap);
        return "finish";
    }

    @RequestMapping("/file")
    public String handleFile(@RequestPart(name = "file") MultipartFile multipartFile) {
        System.out.println("上传文件的文件名:" + multipartFile.getOriginalFilename());
        System.out.println("上传文件的大小:" + multipartFile.getSize());
        System.out.println(multipartFile);
        return "finish";
    }

    @RequestMapping("/header")
    public String handleHeader(@RequestHeader("User-Agent") String userAgent) {
        System.out.println(userAgent);
        return "finish";
    }

    @RequestMapping("/allHeader")
    public String handleAllHeader(@RequestHeader Map headersMap) {
        System.out.println(headersMap);
        return "finish";
    }
}

标签:RequestMapping,String,示例,System,Springboot,println,接收,public,out
From: https://www.cnblogs.com/xl4ng/p/16753282.html

相关文章

  • SpringBoot运行报错
    在SpringBoot启动时报错发现自己写的测试类这个Mapper报错但是Mapper包里面与以前写的一样但是在SPringBoot里面这个Mapper必须要打上注解才能运行......
  • SpringBoot访问Clickhouse执行时报错:org.springframework.beans.factory.UnsatisfiedD
    1依赖信息<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"......
  • Springboot笔记
    SpringBootHelloWorld1.创建Meven工程2.引入依赖pom.xml<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</a......
  • SpringBoot 整合 MyBatis
    本文基于:https://www.bilibili.com/video/BV15b4y1a7yG?p=28&vd_source=cf8900ba33d057d422c588abe5d5290d在pom.xml中导入坐标<dependencies>...<!--引入MyBa......
  • 一个 dubbo 和 springboot 的兼容性问题
    背景介绍最近把dubbo的版本从2.7.3升级到2.7.15时,遇到一个报错Noapplicationconfigfoundorit'snotavalidconfig!,对应的异常栈为:Causedby:java.lang.Illega......
  • springboot整合thymeleaf模板引擎和bootstrap实现增删改查和文件上传
     一、参照第八天任务中的栏目表,使用thymeleaf做为前端展现,完成CRUD及分页操作二、使用springboot+mybatis-plus+redis完成用户登录系统,数据库表users字段名称......
  • SpringBoot 整合 MyBatis
    本文基于:https://www.bilibili.com/video/BV15b4y1a7yG?p=28&vd_source=cf8900ba33d057d422c588abe5d5290d在pom.xml中导入坐标<dependencies>...<!--引入MyB......
  • springboot常见错误
    错误1:运行项目后报如下错误解决方案报错2:​​Failedtoexecutegoalorg.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile(default-compile)onprojectsb​......
  • Redis入门(四):springboot整合redis
    案例一​​demo​​​为​​chnx/springboot/redis01​​创建springboot项目,导入redis依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>s......
  • vue-ant design示例大全——按钮本地css/js资源
    vue-antdesign示例大全——本地css/js资源示例资源来自官网:​​https://www.antdv.com/components/button-cn​​在AntDesignVue中我们提供了五种按钮。主按钮:用于主行......