search
HomeJavajavaTutorialHow to use @RestController annotation to implement http request in SpringBoot

@RestController

@RestController = @Controller @ResponseBody. The two comrades on the right side of the equal sign briefly introduce a few sentences to understand the meaning of our @RestController:

@Controller will be the current The modified class is injected into the SpringBoot IOC container, so that the class is instantiated when the project where the class is located is run. Of course, it also has a semantic effect, which means that this class acts as a Controller.

@ResponseBody Its function in short refers to the data returned by all API interfaces in this class, regardless of your corresponding The method returns Map or other Object, which will be returned to the client in the form of a Json string. I tried it. If the returned type is String, it is still String.

@RestController
@RequestMapping("test")
public class SampleController {

  @GetMapping
  public Map testGet() {
    return new HashMap<string>(){{
      put("name", "springboot");
    }};
  }

  @GetMapping(path = "str")
  public String testGetStr() {
    return "OK";
  }
}</string>

This part of the code returns JSON String for Map, and still String for String

How to use @RestController annotation to implement http request in SpringBoot

How to use @RestController annotation to implement http request in SpringBoot

# #When @RestController is replaced with @Controller, the return value for /test is as follows:

How to use @RestController annotation to implement http request in SpringBoot

The above is the detailed content of How to use @RestController annotation to implement http request in SpringBoot. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor