File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed
src/main/java/io/github/devopsws/demo/service Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,11 @@ Run with Maven command:
1313mvn spring-boot:run
1414```
1515
16+ Change the listen port:
17+ ``` shell
18+ java -jar demo.jar --server.port=8081
19+ ```
20+
1621## OpenAPI definition
1722You can visit it via: http://localhost:8080/v3/api-docs
1823
Original file line number Diff line number Diff line change 11package io .github .devopsws .demo .service ;
22
3+ import java .io .FileOutputStream ;
4+
5+ import org .springframework .util .FileCopyUtils ;
36import org .springframework .web .bind .annotation .PostMapping ;
47import org .springframework .web .bind .annotation .RequestMapping ;
58import org .springframework .web .bind .annotation .RequestParam ;
@@ -16,8 +19,11 @@ public Message<?> upload(@RequestParam("file") MultipartFile file) {
1619 System .out .println ("Received file uploading request" );
1720 Message <String > message = new Message <String >();
1821 if (!file .isEmpty ()) {
19- try {
20- System .out .println ("Uploading file size:" + file .getSize ());
22+ String filename = file .getOriginalFilename ();
23+ try (FileOutputStream out = new FileOutputStream (filename )) {
24+ System .out .println ("Uploading file size: " + file .getSize () + ", name: " + filename );
25+
26+ FileCopyUtils .copy (file .getInputStream (), out );
2127
2228 message .setMessage ("ok" );
2329 } catch (Exception e ) {
Original file line number Diff line number Diff line change 1+ package io .github .devopsws .demo .service ;
2+
3+ import org .springframework .web .bind .annotation .GetMapping ;
4+ import org .springframework .web .bind .annotation .RestController ;
5+
6+ @ RestController ("/" )
7+ public class RootService {
8+
9+ @ GetMapping ("" )
10+ public String index () {
11+ return "Let's learn spring boot!" ;
12+ }
13+ }
You can’t perform that action at this time.
0 commit comments