Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Run with Maven command:
mvn spring-boot:run
```

Change the listen port:
```shell
java -jar demo.jar --server.port=8081
```

## OpenAPI definition
You can visit it via: http://localhost:8080/v3/api-docs

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/io/github/devopsws/demo/service/FileService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.github.devopsws.demo.service;

import java.io.FileOutputStream;

import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -16,8 +19,11 @@ public Message<?> upload(@RequestParam("file") MultipartFile file) {
System.out.println("Received file uploading request");
Message<String> message = new Message<String>();
if (!file.isEmpty()) {
try {
System.out.println("Uploading file size:" + file.getSize());
String filename = file.getOriginalFilename();
try (FileOutputStream out = new FileOutputStream(filename)) {
System.out.println("Uploading file size: " + file.getSize() + ", name: " + filename);

FileCopyUtils.copy(file.getInputStream(), out);

message.setMessage("ok");
} catch (Exception e) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/io/github/devopsws/demo/service/RootService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.devopsws.demo.service;

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

@RestController("/")
public class RootService {

@GetMapping("")
public String index() {
return "Let's learn spring boot!";
}
}
Loading