From 8b2412f428687dc8cd376efe55058e2c40772d0b Mon Sep 17 00:00:00 2001 From: hequan_waynaqua <1669738430@qq.com> Date: Wed, 12 Aug 2020 19:03:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=A8=A1=E5=9D=97):=20=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/test/com/test/BufferedInputFile.java | 17 +++++++++ .../src/main/test/com/test/FileRead.java | 23 +++++++++++ .../test/com/test/{Test.java => NIOTest.java} | 3 +- .../src/main/test/com/test/OSExecute.java | 38 +++++++++++++++++++ .../src/main/test/com/test/TestEOF.java | 20 ++++++++++ .../api/controller/GoodsController.java | 3 +- 6 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 waynboot-generator/src/main/test/com/test/BufferedInputFile.java create mode 100644 waynboot-generator/src/main/test/com/test/FileRead.java rename waynboot-generator/src/main/test/com/test/{Test.java => NIOTest.java} (94%) create mode 100644 waynboot-generator/src/main/test/com/test/OSExecute.java create mode 100644 waynboot-generator/src/main/test/com/test/TestEOF.java diff --git a/waynboot-generator/src/main/test/com/test/BufferedInputFile.java b/waynboot-generator/src/main/test/com/test/BufferedInputFile.java new file mode 100644 index 0000000..004bb25 --- /dev/null +++ b/waynboot-generator/src/main/test/com/test/BufferedInputFile.java @@ -0,0 +1,17 @@ +package com.test; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.stream.Collectors; + +public class BufferedInputFile { + public static void main(String[] args) { + try (BufferedReader reader = new BufferedReader(new FileReader("E:/data.txt"))) { + System.out.println(reader.lines().collect(Collectors.joining("\n"))); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/waynboot-generator/src/main/test/com/test/FileRead.java b/waynboot-generator/src/main/test/com/test/FileRead.java new file mode 100644 index 0000000..df89d0a --- /dev/null +++ b/waynboot-generator/src/main/test/com/test/FileRead.java @@ -0,0 +1,23 @@ +package com.test; + + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +public class FileRead { + public static void main(String[] args) { + try (FileReader fileReader = new FileReader("E:/data.txt")) { + char arr[] = new char[1024]; + int len; + while ((len = fileReader.read(arr)) != -1) { + System.out.println(new String(arr,0 ,len)); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } +} diff --git a/waynboot-generator/src/main/test/com/test/Test.java b/waynboot-generator/src/main/test/com/test/NIOTest.java similarity index 94% rename from waynboot-generator/src/main/test/com/test/Test.java rename to waynboot-generator/src/main/test/com/test/NIOTest.java index 0de4941..9a5415b 100644 --- a/waynboot-generator/src/main/test/com/test/Test.java +++ b/waynboot-generator/src/main/test/com/test/NIOTest.java @@ -6,7 +6,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; -public class Test { +public class NIOTest { private static String name = "E:/data.txt"; private static final int BSIZE = 1024; @@ -27,6 +27,7 @@ public class Test { buff.flip(); while (buff.hasRemaining()) System.out.write(buff.get()); + System.out.println(); System.out.flush(); } } diff --git a/waynboot-generator/src/main/test/com/test/OSExecute.java b/waynboot-generator/src/main/test/com/test/OSExecute.java new file mode 100644 index 0000000..de8f7db --- /dev/null +++ b/waynboot-generator/src/main/test/com/test/OSExecute.java @@ -0,0 +1,38 @@ +package com.test; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class OSExecute { + public static void command(String command) throws Exception { + boolean err = false; + try { + Process process = new ProcessBuilder( + command.split(" ")).start(); + try ( + BufferedReader results = new BufferedReader( + new InputStreamReader( + process.getInputStream(), "gbK")); + BufferedReader errors = new BufferedReader( + new InputStreamReader( + process.getErrorStream())) + ) { + results.lines() + .forEach(System.out::println); + err = errors.lines() + .peek(System.err::println) + .count() > 0; + } + } catch (IOException e) { + throw new RuntimeException(e); + } + if (err) + throw new Exception( + "Errors executing " + command); + } + + public static void main(String[] args) throws Exception { + command("java -version"); + } +} diff --git a/waynboot-generator/src/main/test/com/test/TestEOF.java b/waynboot-generator/src/main/test/com/test/TestEOF.java new file mode 100644 index 0000000..d8b86e0 --- /dev/null +++ b/waynboot-generator/src/main/test/com/test/TestEOF.java @@ -0,0 +1,20 @@ +package com.test; + +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; + +public class TestEOF { + public static void main(String[] args) { + try (DataInputStream in = new DataInputStream(new FileInputStream("E:/data.txt"))) { + while (in.available() != 0) { + System.out.write(in.readByte()); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/GoodsController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/GoodsController.java index 5f245fa..40376dd 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/GoodsController.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/GoodsController.java @@ -4,6 +4,7 @@ import com.wayn.common.util.R; import com.wayn.mobile.api.service.IGoodsDetailService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -15,7 +16,7 @@ public class GoodsController { private IGoodsDetailService iGoodsDetailService; @GetMapping("detail/{goodsId}") - public R detail(Long goodsId) { + public R detail(@PathVariable Long goodsId) { return iGoodsDetailService.getGoodsDetailData(goodsId); } }