From 2d0b4a37d7130dc9fc0596b3265452372458afe9 Mon Sep 17 00:00:00 2001 From: Cool <747682928@qq.com> Date: Wed, 28 Aug 2024 20:47:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 33 ++++++++ pom.xml | 77 +++++++++++++++++++ .../wxappserver/WxappServerApplication.java | 15 ++++ .../wxappserver/config/MybatisPlusConfig.java | 30 ++++++++ .../controller/OrderController.java | 30 ++++++++ .../com/bigdata/wxappserver/entity/Order.java | 32 ++++++++ .../wxappserver/mapper/OrderMapper.java | 7 ++ .../wxappserver/service/OrderService.java | 30 ++++++++ src/main/resources/application.yml | 16 ++++ .../WxappServerApplicationTests.java | 13 ++++ 10 files changed, 283 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/com/bigdata/wxappserver/WxappServerApplication.java create mode 100644 src/main/java/com/bigdata/wxappserver/config/MybatisPlusConfig.java create mode 100644 src/main/java/com/bigdata/wxappserver/controller/OrderController.java create mode 100644 src/main/java/com/bigdata/wxappserver/entity/Order.java create mode 100644 src/main/java/com/bigdata/wxappserver/mapper/OrderMapper.java create mode 100644 src/main/java/com/bigdata/wxappserver/service/OrderService.java create mode 100644 src/main/resources/application.yml create mode 100644 src/test/java/com/bigdata/wxappserver/WxappServerApplicationTests.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5c76e3c --- /dev/null +++ b/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.7.17 + + + com.bigdata + wxapp-server + 0.0.1-SNAPSHOT + wxapp-server + wxapp-server + + 1.8 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + + + com.auth0 + java-jwt + 3.8.3 + + + junit + junit + 4.13.2 + + + org.projectlombok + lombok + 1.18.26 + + + mysql + mysql-connector-java + 8.0.33 + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3.1 + + + + com.alibaba + fastjson + 1.2.83 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + diff --git a/src/main/java/com/bigdata/wxappserver/WxappServerApplication.java b/src/main/java/com/bigdata/wxappserver/WxappServerApplication.java new file mode 100644 index 0000000..6091f55 --- /dev/null +++ b/src/main/java/com/bigdata/wxappserver/WxappServerApplication.java @@ -0,0 +1,15 @@ +package com.bigdata.wxappserver; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@MapperScan("com.bigdata.wxappserver.mapper") +@SpringBootApplication +public class WxappServerApplication { + + public static void main(String[] args) { + SpringApplication.run(WxappServerApplication.class, args); + } + +} diff --git a/src/main/java/com/bigdata/wxappserver/config/MybatisPlusConfig.java b/src/main/java/com/bigdata/wxappserver/config/MybatisPlusConfig.java new file mode 100644 index 0000000..a9d6790 --- /dev/null +++ b/src/main/java/com/bigdata/wxappserver/config/MybatisPlusConfig.java @@ -0,0 +1,30 @@ +package com.bigdata.wxappserver.config; + +import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import org.apache.ibatis.reflection.MetaObject; +import org.springframework.context.annotation.Configuration; + +import java.util.Date; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/08/28/20:18 + * @Description: + */ +@Configuration +public class MybatisPlusConfig implements MetaObjectHandler { + + + @Override + public void insertFill(MetaObject metaObject) { + this.setFieldValByName("createTime", new Date(), metaObject); + this.setFieldValByName("updateTime", new Date(), metaObject); + } + + @Override + public void updateFill(MetaObject metaObject) { + this.setFieldValByName("updateTime", new Date(), metaObject); + } +} diff --git a/src/main/java/com/bigdata/wxappserver/controller/OrderController.java b/src/main/java/com/bigdata/wxappserver/controller/OrderController.java new file mode 100644 index 0000000..9cd8d31 --- /dev/null +++ b/src/main/java/com/bigdata/wxappserver/controller/OrderController.java @@ -0,0 +1,30 @@ +package com.bigdata.wxappserver.controller; + +import com.alibaba.fastjson.JSONObject; +import com.bigdata.wxappserver.service.OrderService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/08/28/20:28 + * @Description: + */ +@RestController +@RequestMapping("order") +public class OrderController { + + @Autowired + OrderService orderService; + + @RequestMapping("addOrUpdate") + public JSONObject addOrUpdate(@RequestBody JSONObject jsonObject){ + return orderService.addOrUpdate(jsonObject); + + } + +} diff --git a/src/main/java/com/bigdata/wxappserver/entity/Order.java b/src/main/java/com/bigdata/wxappserver/entity/Order.java new file mode 100644 index 0000000..10fdd93 --- /dev/null +++ b/src/main/java/com/bigdata/wxappserver/entity/Order.java @@ -0,0 +1,32 @@ +package com.bigdata.wxappserver.entity; + +import com.baomidou.mybatisplus.annotation.*; + +import java.util.Date; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/08/28/20:22 + * @Description: + */ +@TableName("order") +public class Order { + @TableId(type = IdType.AUTO) + private Integer id; + + private String username; + private String phone; + + private Integer goodId; + private String address; + private Date deliveryTime; + + @TableField(fill= FieldFill.INSERT) + private Date createTime; + @TableField(fill= FieldFill.INSERT_UPDATE) + private Date updateTime; + @TableLogic + private Integer isDelete; +} diff --git a/src/main/java/com/bigdata/wxappserver/mapper/OrderMapper.java b/src/main/java/com/bigdata/wxappserver/mapper/OrderMapper.java new file mode 100644 index 0000000..79059e5 --- /dev/null +++ b/src/main/java/com/bigdata/wxappserver/mapper/OrderMapper.java @@ -0,0 +1,7 @@ +package com.bigdata.wxappserver.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.bigdata.wxappserver.entity.Order; + +public interface OrderMapper extends BaseMapper { +} diff --git a/src/main/java/com/bigdata/wxappserver/service/OrderService.java b/src/main/java/com/bigdata/wxappserver/service/OrderService.java new file mode 100644 index 0000000..0b16efc --- /dev/null +++ b/src/main/java/com/bigdata/wxappserver/service/OrderService.java @@ -0,0 +1,30 @@ +package com.bigdata.wxappserver.service; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.bigdata.wxappserver.entity.Order; +import com.bigdata.wxappserver.mapper.OrderMapper; +import org.springframework.stereotype.Service; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/08/28/20:28 + * @Description: + */ +@Service +public class OrderService extends ServiceImpl { + + + public JSONObject addOrUpdate(JSONObject jsonObject) { + Order order = jsonObject.toJavaObject(Order.class); + if (order==null){ + return new JSONObject().fluentPut("success",false).fluentPut("message","参数错误"); + } + // TODO 判空 + boolean success = saveOrUpdate(order); + return new JSONObject().fluentPut("message","success").fluentPut("success",success); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..d22acf9 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,16 @@ +spring: + application: + name: wxapp-server + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://62.234.217.137:3306/wxapp?useUnicode=true&characterEncoding=UTF-8 + username: root + password: nWZpHMb8mNxWE5Xk +server: + port: 8088 + +# Mybatis-plus?? +mybatis-plus: + mapper-locations: classpath*:/mapper/*Mapper.xml + configuration: + map-underscore-to-camel-case: true diff --git a/src/test/java/com/bigdata/wxappserver/WxappServerApplicationTests.java b/src/test/java/com/bigdata/wxappserver/WxappServerApplicationTests.java new file mode 100644 index 0000000..37c2f13 --- /dev/null +++ b/src/test/java/com/bigdata/wxappserver/WxappServerApplicationTests.java @@ -0,0 +1,13 @@ +package com.bigdata.wxappserver; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class WxappServerApplicationTests { + + @Test + void contextLoads() { + } + +}