From 8f9b9a4e742c68f5d952f2ad9d37913cd756ddce Mon Sep 17 00:00:00 2001 From: zx <649359073@qq.com> Date: Tue, 30 Jun 2020 23:36:42 +0800 Subject: [PATCH] 17 --- .../java/com/book/demo/BookApplication.java | 2 +- .../book/demo/controller/BookController.java | 47 ++++++++++++------- .../book/demo/controller/CartController.java | 8 ++-- .../book/demo/controller/OrderController.java | 8 ++-- .../book/demo/controller/UserController.java | 14 +++--- src/main/resources/application.properties | 2 +- 6 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/book/demo/BookApplication.java b/src/main/java/com/book/demo/BookApplication.java index d8bc1fa..7e561b9 100644 --- a/src/main/java/com/book/demo/BookApplication.java +++ b/src/main/java/com/book/demo/BookApplication.java @@ -9,7 +9,7 @@ public class BookApplication { public static void main(String[] args) { SpringApplication.run(BookApplication.class, args); - System.out.println("http://127.0.0.1:8090/query?username=admin1"); + System.out.println("http://127.0.0.1:8099/query?username=admin1"); } } diff --git a/src/main/java/com/book/demo/controller/BookController.java b/src/main/java/com/book/demo/controller/BookController.java index 097d880..d742f78 100644 --- a/src/main/java/com/book/demo/controller/BookController.java +++ b/src/main/java/com/book/demo/controller/BookController.java @@ -23,7 +23,7 @@ public class BookController { if(books.length<=0){ res.setCode(-1); res.setMsg("当前系统没有书籍信息"); - res.data=null; + res.data.clear(); } else{ res.setCode(0); @@ -40,19 +40,34 @@ public class BookController { @ResponseBody @GetMapping("/getbooks") public Result getAllBooksByKind(@RequestParam("kind")String kind){ - Book []books=bookMapper.getBooksByKind(kind); - if(books.length<=0){ - res.setCode(-1); - res.setMsg("当前系统没有此类别书籍信息"); - res.data=null; - } - else{ - res.setCode(0); - res.setMsg("获取成功"); - res.data.clear(); - for (Book book : books) { - res.data.add(book); + try { + System.out.println(kind); + if(kind.equals("推荐")){ + Book []books=bookMapper.getAll(); + res.setCode(0); + res.data.clear(); + res.setMsg("获取成功"); + for (Book book : books) { + res.data.add(book); + } } + else { + Book[] books = bookMapper.getBooksByKind(kind); + if (books.length <= 0) { + res.setCode(-1); + res.setMsg("当前系统没有此类别书籍信息"); + res.data.clear(); + } else { + res.setCode(0); + res.setMsg("获取成功"); + res.data.clear(); + for (Book book : books) { + res.data.add(book); + } + } + } + }catch (Exception e){ + } return res; } @@ -65,7 +80,7 @@ public class BookController { if(books.length<=0){ res.setCode(-1); res.setMsg("当前系统没有相关书籍信息"); - res.data=null; + res.data.clear(); } else{ res.setCode(0); @@ -91,7 +106,7 @@ public class BookController { res.setCode(-1); res.setMsg("添加失败"); } - res.data=null; + res.data.clear(); return res; } @@ -108,7 +123,7 @@ public class BookController { res.setCode(-1); res.setMsg("删除失败"); } - res.data=null; + res.data.clear(); return res; } diff --git a/src/main/java/com/book/demo/controller/CartController.java b/src/main/java/com/book/demo/controller/CartController.java index daeda40..c64c61b 100644 --- a/src/main/java/com/book/demo/controller/CartController.java +++ b/src/main/java/com/book/demo/controller/CartController.java @@ -26,7 +26,7 @@ public class CartController { @GetMapping("/addintocart") public Result AddBookIn(@RequestParam("username")String username,@RequestParam("bookname") String bookname){ //把数量默认都设为1 - + System.out.println("u:"+username+"\tb:"+bookname); Book book=bookMapper.searchBookbyName(bookname); int state=cartMapper.insertItem(username,bookname,book.getPrice()); @@ -38,7 +38,7 @@ public class CartController { res.setCode(-1); res.setMsg("添加失败"); } - res.data=null; + res.data.clear(); return res; } @@ -56,7 +56,7 @@ public class CartController { res.setCode(-1); res.setMsg("清空失败"); } - res.data=null; + res.data.clear(); return res; } @@ -73,7 +73,7 @@ public class CartController { res.setCode(-1); res.setMsg("数量更新失败"); } - res.data=null; + res.data.clear(); return res; } } diff --git a/src/main/java/com/book/demo/controller/OrderController.java b/src/main/java/com/book/demo/controller/OrderController.java index f7f802b..cae44f9 100644 --- a/src/main/java/com/book/demo/controller/OrderController.java +++ b/src/main/java/com/book/demo/controller/OrderController.java @@ -44,7 +44,7 @@ public class OrderController { else{ res.setCode(-1); res.setMsg("暂无订单"); - res.data=null; + res.data.clear(); } return res; } @@ -62,7 +62,7 @@ public class OrderController { res.setCode(-1); res.setMsg("更新订单失败"); } - res.data=null; + res.data.clear(); return res; } @@ -81,7 +81,7 @@ public class OrderController { res.setCode(-1); res.setMsg("生成订单失败"); } - res.data=null; + res.data.clear(); return res; } @@ -98,7 +98,7 @@ public class OrderController { res.setCode(-1); res.setMsg("删除订单失败"); } - res.data=null; + res.data.clear(); return res; } } diff --git a/src/main/java/com/book/demo/controller/UserController.java b/src/main/java/com/book/demo/controller/UserController.java index 41a85bb..367e215 100644 --- a/src/main/java/com/book/demo/controller/UserController.java +++ b/src/main/java/com/book/demo/controller/UserController.java @@ -27,7 +27,7 @@ public class UserController { else { res.setCode(-1); res.setMsg("数据非法,无此用户"); - res.data=null; + res.data.clear(); } return res; } @@ -41,11 +41,11 @@ public class UserController { if (user1 == null) { res.setCode(-1); res.setMsg("用户不存在"); - res.data = null; + res.data.clear(); } else if (!user1.getPassword().trim().equals(user.getPassword().trim())) { res.setCode(-2); res.setMsg("密码错误"); - res.data = null; + res.data.clear(); } else if (user1.getUserstatus() == 0) { res.setCode(0); res.setMsg("用户登录"); @@ -68,7 +68,7 @@ public class UserController { if(user1!=null){ res.setCode(-1); res.setMsg("用户已存在"); - res.data=null; + res.data.clear(); } else{ user1=user; @@ -80,7 +80,7 @@ public class UserController { res.setCode(-2); res.setMsg("注册失败,稍后再试"); } - res.data = null; + res.data.clear(); } return res; } @@ -103,7 +103,7 @@ public class UserController { res.setMsg("删除失败"); } } - res.data = null; + res.data.clear(); return res; } @@ -116,7 +116,7 @@ public class UserController { if (user.length <= 0) { res.setCode(-1); res.setMsg("用户数据查询失败"); - res.data = null; + res.data.clear(); } else { res.setCode(0); res.setMsg("用户数据查询成功"); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 63a464c..03f66bb 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,4 @@ -server.port=8090 +server.port=8099 spring.datasource.url=jdbc:mysql://localhost:3306/test02?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8