Last active
September 29, 2023 07:49
-
-
Save martin-mfg/9bae0392ee3a26bac5cc388a6c8b1469 to your computer and use it in GitHub Desktop.
please see 1st comment below
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package demo; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.http.HttpStatus; | |
import org.springframework.http.ResponseEntity; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.validation.annotation.Validated; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RequestMethod; | |
import org.springframework.web.bind.annotation.RequestParam; | |
@Validated | |
@Controller | |
@SpringBootApplication | |
public class DemoApp { | |
public static void main(String[] args) { | |
SpringApplication.run(DemoApp.class, args); | |
} | |
@RequestMapping( | |
method = RequestMethod.GET, | |
value = "/todos/1/", | |
produces = {"text/plain"} | |
) | |
public ResponseEntity<String> exampleOperation( | |
@RequestParam(value = "par1", required = false, defaultValue = "true") Boolean par1, | |
@RequestParam(value = "par2", required = false, defaultValue = "1.23") Float par2 | |
) { | |
return new ResponseEntity<>(par1 + " " + par2, HttpStatus.OK); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>org.openapitools</groupId> | |
<artifactId>openapi-spring</artifactId> | |
<name>openapi-spring</name> | |
<version>1.0.0</version> | |
<parent> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-parent</artifactId> | |
<version>3.1.4</version> | |
<relativePath/> <!-- lookup parent from repository --> | |
</parent> | |
<dependencies> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-web</artifactId> | |
</dependency> | |
</dependencies> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Purpose
Demo Spring Boot server which to show that even with
defaultValue
, parameters can benull
.How to run
mvn compile exec:java '-Dexec.mainClass=demo.DemoApp'
Results
http://localhost:8080/todos/1/?par1=true&par2=3&x=y
http://localhost:8080/todos/1/?par1=%20&par2=%20&x=y
When using the latest Spring 6.1.0-M5, the 2nd request results in an HTTP status code 500.