From af19584a325beffa288079ba754f770c2711c2e5 Mon Sep 17 00:00:00 2001 From: wyz Date: Sun, 10 Jan 2021 04:21:19 +0800 Subject: [PATCH] done --- README.md | 55 +++++- src/main/java/com/wyz/demo/config/BasicConfig.java | 2 +- .../java/com/wyz/demo/config/MapperConfig.java | 6 + .../com/wyz/demo/controller/OrderController.java | 51 +++++ .../java/com/wyz/demo/dao/OrderRepository.java | 17 ++ src/main/java/com/wyz/demo/dao/UserRepository.java | 29 +-- src/main/java/com/wyz/demo/dto/OrderDTO.java | 18 +- src/main/java/com/wyz/demo/po/OrderPO.java | 20 +- .../java/com/wyz/demo/service/OrderService.java | 21 +++ .../wyz/demo/service/impl/OrderServiceImpl.java | 72 +++++++ .../com/wyz/demo/service/impl/UserServiceImpl.java | 4 +- src/main/java/com/wyz/demo/vo/OrderVO.java | 18 ++ src/main/resources/000application.properties | 1 + src/main/resources/application.properties | 1 - src/main/resources/application.yml | 10 + src/main/resources/mapper/OrderMapper.xml | 35 ++++ src/main/resources/mapper/UserMapper.xml | 13 +- src/main/resources/mybatis-config.xml | 1 + src/main/resources/static/BookInfo.html | 50 ++++- src/main/resources/static/Cart.html | 53 +++++- src/main/resources/static/FriendLink.html | 55 +++++- src/main/resources/static/Index.html | 94 +++------- src/main/resources/static/Login.html | 53 +++++- src/main/resources/static/NewOrder.html | 207 +++++++++++++++++++++ src/main/resources/static/Order.html | 207 +++++++++++++++------ src/main/resources/static/OrderInfo.html | 50 ++++- src/main/resources/static/Register.html | 51 ++++- src/main/resources/static/UserInfo.html | 66 ++++++- src/main/resources/static/jquery.js | 2 - table.sql | 32 +++- 30 files changed, 1063 insertions(+), 231 deletions(-) create mode 100644 src/main/java/com/wyz/demo/controller/OrderController.java create mode 100644 src/main/java/com/wyz/demo/dao/OrderRepository.java create mode 100644 src/main/java/com/wyz/demo/service/OrderService.java create mode 100644 src/main/java/com/wyz/demo/service/impl/OrderServiceImpl.java create mode 100644 src/main/java/com/wyz/demo/vo/OrderVO.java create mode 100644 src/main/resources/000application.properties delete mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/application.yml create mode 100644 src/main/resources/mapper/OrderMapper.xml create mode 100644 src/main/resources/static/NewOrder.html delete mode 100644 src/main/resources/static/jquery.js diff --git a/README.md b/README.md index f6824b7..e743da0 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,19 @@ # 快递代取系统 +## 版权 + +用的是一个大佬放在github上的前端代码,但是我现在找不到是哪个了 + +如果侵权的话,请联系我:) + ## 介绍 -前后端分离 -后端使用springboot -提供json的api给前端 +- 前后端分离 + +- 前端用jquery的ajax发送请求 + +- 后端使用springboot + 提供json的api给前端 ## 软件架构 @@ -12,13 +21,13 @@ ## 安装教程 -1. xxxx -2. xxxx -3. xxxx +1. 先在mysql中跑一下table.sql文件,创建表 +2. 改一下src/main/resources/mybatis-config.xml(改一下db,还有密码) +3. 用idea打开直接运行Application即可 ## 使用说明 -1. xxxx +1. 随便点就行 2. xxxx 3. xxxx @@ -181,3 +190,35 @@ ajax那边不管data的数据有没有加上JSON.stringify()都不行 把dataType删了就行 + + + + +## mybatis一级缓存的禁用 + +因为mybatis有一级缓存,作同一个查询时,会复用上次的结果 + +自己通过cmd操作mysql(修改表中的数据),不会使缓存失效 + +只有通过mybatis修改数据,才会使一级缓存失效 + + + +所以怎么禁用一级缓存呢? + +==配置文件== + +```yaml +mybatis: + configuration: + cache-enabled: false #禁用二级缓存 + local-cache-scope: session #一级缓存指定为session级别 + local-cache-scope: statement #一级缓存指定为statement级别, 相当于禁用一级缓存 +``` + +==手动清除== + +```java +session.clearCache(); +``` + diff --git a/src/main/java/com/wyz/demo/config/BasicConfig.java b/src/main/java/com/wyz/demo/config/BasicConfig.java index 3bce53c..4b6456b 100644 --- a/src/main/java/com/wyz/demo/config/BasicConfig.java +++ b/src/main/java/com/wyz/demo/config/BasicConfig.java @@ -17,7 +17,7 @@ public class BasicConfig { // 提供SqlSession @Bean - @Scope("prototype") +// @Scope("prototype") public SqlSession sqlSession(){ try{ InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml"); diff --git a/src/main/java/com/wyz/demo/config/MapperConfig.java b/src/main/java/com/wyz/demo/config/MapperConfig.java index b87a526..215290e 100644 --- a/src/main/java/com/wyz/demo/config/MapperConfig.java +++ b/src/main/java/com/wyz/demo/config/MapperConfig.java @@ -1,5 +1,6 @@ package com.wyz.demo.config; +import com.wyz.demo.dao.OrderRepository; import com.wyz.demo.dao.UserRepository; import com.wyz.demo.service.UserService; import org.apache.ibatis.session.SqlSession; @@ -17,4 +18,9 @@ public class MapperConfig { public UserRepository userRepository(){ return sqlSession.getMapper(UserRepository.class); } + + @Bean + public OrderRepository orderRepository(){ + return sqlSession.getMapper(OrderRepository.class); + } } diff --git a/src/main/java/com/wyz/demo/controller/OrderController.java b/src/main/java/com/wyz/demo/controller/OrderController.java new file mode 100644 index 0000000..1032cda --- /dev/null +++ b/src/main/java/com/wyz/demo/controller/OrderController.java @@ -0,0 +1,51 @@ +package com.wyz.demo.controller; + +import com.wyz.demo.dto.OrderDTO; +import com.wyz.demo.service.OrderService; +import com.wyz.demo.vo.OrderVO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpSession; +import java.util.List; + + +@Slf4j +@RestController +@RequestMapping("/order") +public class OrderController { + + @Autowired + private OrderService orderService; + + + /** + * 查询订单 + */ + @RequestMapping(value = "/getAll", produces = "application/json") + public List getAll(HttpSession sess){ + String username = (String)sess.getAttribute("username"); + if(username==null){ + log.error("{session中没有用户名:还未登录}"); + return null; + }else{ + List orders = orderService.getAll(username); + return orders; + } + } + + + /** + * 提交订单 + */ + @PostMapping(value = "/commit") + public void commit(@RequestBody OrderDTO orderDTO, HttpSession sess){ + log.info("新订单为:{}",orderDTO); + orderService.addOrder(orderDTO,sess); + } + +} diff --git a/src/main/java/com/wyz/demo/dao/OrderRepository.java b/src/main/java/com/wyz/demo/dao/OrderRepository.java new file mode 100644 index 0000000..4838208 --- /dev/null +++ b/src/main/java/com/wyz/demo/dao/OrderRepository.java @@ -0,0 +1,17 @@ +package com.wyz.demo.dao; + +import com.wyz.demo.po.OrderPO; + +import java.util.List; + +public interface OrderRepository { + + + // 根据用户id查订单 + public List getOrders(int sender_id); + + + // 提交订单 + public void addOrder(OrderPO orderPO); + +} diff --git a/src/main/java/com/wyz/demo/dao/UserRepository.java b/src/main/java/com/wyz/demo/dao/UserRepository.java index 5e8f3e4..72feee0 100644 --- a/src/main/java/com/wyz/demo/dao/UserRepository.java +++ b/src/main/java/com/wyz/demo/dao/UserRepository.java @@ -8,28 +8,35 @@ import java.util.List; public interface UserRepository { - // 注册用户(添加) + // 添加用户 public void addUser(UserPO user); /** * 判断用户名是否存在 + * 根据用户名获取用户 * @return */ - public UserPO selectUserByUsername(String username); + public UserPO getUserByUsername(String username); -// /** -// * 判断密码是否正确 -// * @param username fw -// * @Param password e fe -// * @return -// */ -// public UserPO checkPassword(String username, String password); + /** + * 根据 username 获取 用户id + * @Param username + * @return id + */ + public int getIdByUsername(String username); + + /** + * 根据 用户id 获取 username + * @Param id + * @return username + */ + public String getUsernameById(int id); - // 查找用户: 根据id - public UserPO findUserById(int id); +// // 查找用户: 根据id +// public UserPO findUserById(int id); } diff --git a/src/main/java/com/wyz/demo/dto/OrderDTO.java b/src/main/java/com/wyz/demo/dto/OrderDTO.java index 20ec927..8670429 100644 --- a/src/main/java/com/wyz/demo/dto/OrderDTO.java +++ b/src/main/java/com/wyz/demo/dto/OrderDTO.java @@ -2,18 +2,14 @@ package com.wyz.demo.dto; import lombok.Data; +import java.io.Serializable; import java.util.Date; @Data -public class OrderDTO { - - public int orderId; - public String description; - public Date datetime; - public String location; - public String comment; - public Date timestamp; - public int senderId; - public int receiverId; - public String status; +public class OrderDTO implements Serializable { + public String description; // 订单描述 + public Date when; // 快递要什么时候送到 + public String location; // 快递在哪里 + public int price; // 价钱 + public String comment; // 备注 } diff --git a/src/main/java/com/wyz/demo/po/OrderPO.java b/src/main/java/com/wyz/demo/po/OrderPO.java index a8e5bc6..48d9668 100644 --- a/src/main/java/com/wyz/demo/po/OrderPO.java +++ b/src/main/java/com/wyz/demo/po/OrderPO.java @@ -7,16 +7,16 @@ import java.util.Date; @Data public class OrderPO { - public int orderId; - public String description; - public Date datetime; - public String location; - public String comment; - public Date timestamp; - public int senderId; - public int receiverId; - public String status; - + int id; + String description; + Date when; + String location; + int senderId; + int receiverId; + int price; + String status; + String comment; + Date timestamp; } diff --git a/src/main/java/com/wyz/demo/service/OrderService.java b/src/main/java/com/wyz/demo/service/OrderService.java new file mode 100644 index 0000000..34a7606 --- /dev/null +++ b/src/main/java/com/wyz/demo/service/OrderService.java @@ -0,0 +1,21 @@ +package com.wyz.demo.service; + +import com.wyz.demo.dto.OrderDTO; +import com.wyz.demo.vo.OrderVO; + +import javax.servlet.http.HttpSession; +import java.util.List; + +public interface OrderService { + + /** + * 获取全部订单 + */ + public List getAll(String username); + + + /** + * 提交订单 + */ + public void addOrder(OrderDTO orderDTO, HttpSession sess); +} diff --git a/src/main/java/com/wyz/demo/service/impl/OrderServiceImpl.java b/src/main/java/com/wyz/demo/service/impl/OrderServiceImpl.java new file mode 100644 index 0000000..0dbf734 --- /dev/null +++ b/src/main/java/com/wyz/demo/service/impl/OrderServiceImpl.java @@ -0,0 +1,72 @@ +package com.wyz.demo.service.impl; + +import com.wyz.demo.dao.OrderRepository; +import com.wyz.demo.dao.UserRepository; +import com.wyz.demo.dto.OrderDTO; +import com.wyz.demo.po.OrderPO; +import com.wyz.demo.service.OrderService; +import com.wyz.demo.vo.OrderVO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpSession; +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Service +public class OrderServiceImpl implements OrderService { + + + @Autowired + private UserRepository userRepository; + + @Autowired + private OrderRepository orderRepository; + + /** + * 获取全部订单 - 根据用户名 + * @Param username 用户名 + */ + @Override + public List getAll(String username) { + int sender_id = userRepository.getIdByUsername(username); + List orders = orderRepository.getOrders(sender_id); + + + List res = new ArrayList<>(); + for (OrderPO orderPO : orders) { + OrderVO orderVO = new OrderVO(); + + orderVO.setTimestamp(orderPO.getTimestamp()); + orderVO.setDescription(orderPO.getDescription()); + orderVO.setPrice(orderPO.getPrice()); + String receiver = userRepository.getUsernameById(orderPO.getReceiverId()); +// log.info("receiver-id:{}",orderPO.getReceiverId()); +// log.info("receiver:{}",receiver); + orderVO.setReceiver(receiver); + orderVO.setStatus(orderPO.getStatus()); + + res.add(orderVO); + } + + + return res; + } + + @Override + public void addOrder(OrderDTO orderDTO, HttpSession sess) { + + OrderPO orderPO = new OrderPO(); + + orderPO.setDescription(orderDTO.getDescription()); + orderPO.setWhen(orderDTO.getWhen()); + orderPO.setLocation(orderDTO.getLocation()); + orderPO.setSenderId(userRepository.getIdByUsername((String)sess.getAttribute("username"))); + orderPO.setPrice(orderDTO.getPrice()); + orderPO.setComment(orderDTO.getComment()); + + orderRepository.addOrder(orderPO); + } +} diff --git a/src/main/java/com/wyz/demo/service/impl/UserServiceImpl.java b/src/main/java/com/wyz/demo/service/impl/UserServiceImpl.java index 0e02dc5..4bc7d29 100644 --- a/src/main/java/com/wyz/demo/service/impl/UserServiceImpl.java +++ b/src/main/java/com/wyz/demo/service/impl/UserServiceImpl.java @@ -37,7 +37,7 @@ public class UserServiceImpl implements UserService { log.info("请求注册的手机号是:{}",userDTO.getPhone()); Message msg = new Message(); - UserPO userPO = userRepository.selectUserByUsername(userDTO.getUsername()); //判断用户名是否存在 + UserPO userPO = userRepository.getUserByUsername(userDTO.getUsername()); //判断用户名是否存在 if(userPO!=null){ msg.setFlag(-3); msg.setMsg("该用户名已经注册"); @@ -77,7 +77,7 @@ public class UserServiceImpl implements UserService { log.info("请求登录的密码是:{}",userDTO.getPassword()); Message msg = new Message(); - UserPO userPO = userRepository.selectUserByUsername(userDTO.getUsername()); //判断用户名是否存在 + UserPO userPO = userRepository.getUserByUsername(userDTO.getUsername()); //判断用户名是否存在 if(userPO == null){ msg.setFlag(-1); diff --git a/src/main/java/com/wyz/demo/vo/OrderVO.java b/src/main/java/com/wyz/demo/vo/OrderVO.java new file mode 100644 index 0000000..5f439b9 --- /dev/null +++ b/src/main/java/com/wyz/demo/vo/OrderVO.java @@ -0,0 +1,18 @@ +package com.wyz.demo.vo; + + +import lombok.Data; + +import java.util.Date; + +@Data +public class OrderVO { + Date timestamp; + String description; + int price; + String receiver; + String status; +} + + + diff --git a/src/main/resources/000application.properties b/src/main/resources/000application.properties new file mode 100644 index 0000000..4d360de --- /dev/null +++ b/src/main/resources/000application.properties @@ -0,0 +1 @@ +server.port=8081 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 4d360de..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -server.port=8081 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..fc30e2b --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,10 @@ + +mybatis: + configuration: + cache-enabled: false #禁用二级缓存 +# local-cache-scope: session #一级缓存指定为session级别 + local-cache-scope: statement #一级缓存指定为statement级别, 相当于禁用一级缓存 + + +server: + port: 8081 \ No newline at end of file diff --git a/src/main/resources/mapper/OrderMapper.xml b/src/main/resources/mapper/OrderMapper.xml new file mode 100644 index 0000000..5aa94e3 --- /dev/null +++ b/src/main/resources/mapper/OrderMapper.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + insert into `order` + (`description`,`when`,`location`,`sender_id`,`receiver_id`, + `price`,`status`,`comment`,`timestamp`) + values + (#{description},#{when},#{location},#{senderId},null, + #{price},"待接单",#{comment},now()) + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/UserMapper.xml index 4320d66..fd4db79 100644 --- a/src/main/resources/mapper/UserMapper.xml +++ b/src/main/resources/mapper/UserMapper.xml @@ -10,15 +10,18 @@ insert into user (username,password,phone) values (#{username},#{password}, #{phone}) - - + select * from user where username = #{username} + - + select username from `user` where id = #{id} + \ No newline at end of file diff --git a/src/main/resources/mybatis-config.xml b/src/main/resources/mybatis-config.xml index 023eb94..44457ea 100644 --- a/src/main/resources/mybatis-config.xml +++ b/src/main/resources/mybatis-config.xml @@ -40,6 +40,7 @@ 放在resources目录下 --> + \ No newline at end of file diff --git a/src/main/resources/static/BookInfo.html b/src/main/resources/static/BookInfo.html index c1d686f..6a71980 100644 --- a/src/main/resources/static/BookInfo.html +++ b/src/main/resources/static/BookInfo.html @@ -19,7 +19,46 @@ } + + + diff --git a/src/main/resources/static/Cart.html b/src/main/resources/static/Cart.html index d33757b..99f62d0 100644 --- a/src/main/resources/static/Cart.html +++ b/src/main/resources/static/Cart.html @@ -23,7 +23,49 @@ } + + + + + + diff --git a/src/main/resources/static/FriendLink.html b/src/main/resources/static/FriendLink.html index da31463..38c09b6 100644 --- a/src/main/resources/static/FriendLink.html +++ b/src/main/resources/static/FriendLink.html @@ -60,14 +60,54 @@ + + + + + diff --git a/src/main/resources/static/Index.html b/src/main/resources/static/Index.html index 43657d0..25da343 100644 --- a/src/main/resources/static/Index.html +++ b/src/main/resources/static/Index.html @@ -42,12 +42,11 @@ success: function (data) { if(data["flag"] < 0){ // 还没登录 - $("#logout").hide(); + $("#register").show(); + $("#login").show(); }else{ // 已经登录了 - $("#register").hide(); - $("#login").hide(); - + $("#logout").show(); } }, error: function () { @@ -81,19 +80,20 @@ - 图书商城 + 快递代取系统 @@ -101,19 +136,19 @@

用户登录

+
-
+
-
@@ -154,7 +189,7 @@

免责声明

-

放心, 我们会负责的

+

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.

diff --git a/src/main/resources/static/NewOrder.html b/src/main/resources/static/NewOrder.html new file mode 100644 index 0000000..33858cd --- /dev/null +++ b/src/main/resources/static/NewOrder.html @@ -0,0 +1,207 @@ + + + + + + + + + + + 注册 + + + + + + + + + + + + + + +
+
+
+

发起新订单

+
+ +
+ + +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ + + + +
+
+ +
+
+ +
+
+ +
+
+ +
+ + + + + + + + + +
+
+ + + + + + \ No newline at end of file diff --git a/src/main/resources/static/Order.html b/src/main/resources/static/Order.html index d3f9ebc..612a5cb 100644 --- a/src/main/resources/static/Order.html +++ b/src/main/resources/static/Order.html @@ -8,7 +8,8 @@ - + + 订单 + + + + +
+ +

我的订单

+ +
-
订单编号
-
订单状态
-
商品数量
-
订单总价
-
操作
+
发布时间
+
描述
+
价格
+
接单人
+
状态
+
操作
+ + +
+ + + + + + + + + + + + + +
+ +
-
ahiudsfhjk-23423-23asd-12
-
未付款
-
12
-
1231.00元
-
- - - -
-
-
-
ahiudsfhjk-23423-23asd-12
-
未付款
-
12
-
1231.00元
-
- - - -
-
-
-
ahiudsfhjk-23423-23asd-12
-
未付款
-
12
-
1231.00元
-
- - - -
-
-
-
ahiudsfhjk-23423-23asd-12
-
未付款
-
12
-
1231.00元
-
- - -
+

点击显示更多

- -
+
\ No newline at end of file diff --git a/src/main/resources/static/OrderInfo.html b/src/main/resources/static/OrderInfo.html index 74cfb2e..e9437e9 100644 --- a/src/main/resources/static/OrderInfo.html +++ b/src/main/resources/static/OrderInfo.html @@ -57,7 +57,46 @@ }) + + + diff --git a/src/main/resources/static/Register.html b/src/main/resources/static/Register.html index 1b37490..1eaa937 100644 --- a/src/main/resources/static/Register.html +++ b/src/main/resources/static/Register.html @@ -24,13 +24,11 @@ @@ -69,20 +101,23 @@ - 图书商城 + 快递代取系统
@@ -93,9 +128,8 @@

用户注册

-
- +
@@ -179,7 +213,6 @@
-
diff --git a/src/main/resources/static/UserInfo.html b/src/main/resources/static/UserInfo.html index 2eb547e..a177a7f 100644 --- a/src/main/resources/static/UserInfo.html +++ b/src/main/resources/static/UserInfo.html @@ -8,11 +8,13 @@ - + + + 个人中心