From 8736c3ea751b32eda0dc0102e0a62f387594bfbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=91=AB?= <1173628408@qq.com> Date: Fri, 26 Jul 2024 09:08:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E8=80=838?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 38 ++++++ .idea/.gitignore | 8 ++ .idea/CamelCaseConfigNew.xml | 20 +++ .idea/JavaSceneConfigState.xml | 6 + .idea/encodings.xml | 8 ++ .idea/inspectionProfiles/Project_Default.xml | 5 + .idea/misc.xml | 58 ++++++++ .idea/uiDesigner.xml | 124 ++++++++++++++++++ .idea/vcs.xml | 6 + pom.xml | 46 +++++++ src/main/java/com/muyu/Rik08Application.java | 11 ++ .../com/muyu/controller/BillController.java | 40 ++++++ src/main/java/com/muyu/domain/Bill.java | 21 +++ src/main/java/com/muyu/mapper/BillMapper.java | 20 +++ .../java/com/muyu/service/BillService.java | 17 +++ .../muyu/service/impl/BillServiceImpl.java | 33 +++++ src/main/resources/application.properties | 27 ++++ src/main/resources/mapper/BillMapper.xml | 17 +++ 18 files changed, 505 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/CamelCaseConfigNew.xml create mode 100644 .idea/JavaSceneConfigState.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 pom.xml create mode 100644 src/main/java/com/muyu/Rik08Application.java create mode 100644 src/main/java/com/muyu/controller/BillController.java create mode 100644 src/main/java/com/muyu/domain/Bill.java create mode 100644 src/main/java/com/muyu/mapper/BillMapper.java create mode 100644 src/main/java/com/muyu/service/BillService.java create mode 100644 src/main/java/com/muyu/service/impl/BillServiceImpl.java create mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/mapper/BillMapper.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/CamelCaseConfigNew.xml b/.idea/CamelCaseConfigNew.xml new file mode 100644 index 0000000..0db1918 --- /dev/null +++ b/.idea/CamelCaseConfigNew.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/.idea/JavaSceneConfigState.xml b/.idea/JavaSceneConfigState.xml new file mode 100644 index 0000000..39245be --- /dev/null +++ b/.idea/JavaSceneConfigState.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..63574ec --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..8d66637 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..73d2610 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + Android + + + CorrectnessLintAndroid + + + Gradle + + + Kotlin + + + LintAndroid + + + Maven + + + MavenMigrationKotlin + + + MigrationKotlin + + + OSGi + + + Probable bugsGradle + + + + + Android + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ea93be8 --- /dev/null +++ b/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + com.muyu + billManager + 1.0-SNAPSHOT + + + 8 + 8 + UTF-8 + + + org.springframework.boot + spring-boot-starter-parent + 2.7.15 + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-web + + + mysql + mysql-connector-java + 8.0.33 + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.3.1 + + + org.projectlombok + lombok + + + diff --git a/src/main/java/com/muyu/Rik08Application.java b/src/main/java/com/muyu/Rik08Application.java new file mode 100644 index 0000000..a67f035 --- /dev/null +++ b/src/main/java/com/muyu/Rik08Application.java @@ -0,0 +1,11 @@ +package com.muyu; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Rik08Application { + public static void main(String[] args) { + SpringApplication.run(Rik08Application.class,args); + } +} diff --git a/src/main/java/com/muyu/controller/BillController.java b/src/main/java/com/muyu/controller/BillController.java new file mode 100644 index 0000000..6d2c35f --- /dev/null +++ b/src/main/java/com/muyu/controller/BillController.java @@ -0,0 +1,40 @@ +package com.muyu.controller; + +import com.muyu.domain.Bill; +import com.muyu.service.BillService; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @Author: WangXin + * @date: 2024/7/26 + * @Description: + * @Version 1.0.0 + */ +@RestController +@RequestMapping("bill") +public class BillController { + @Resource + private BillService billService; + + /** + * 查詢所有 + * @return + */ + @GetMapping("/findAll") + public List findAll(){ + return billService.findAll(); + } + + /** + * 添加 + * @param bill + * @return + */ + @PostMapping("/add") + public String add(@RequestBody Bill bill){ + return billService.add(bill)>0?"添加成功":"添加失败"; + } +} diff --git a/src/main/java/com/muyu/domain/Bill.java b/src/main/java/com/muyu/domain/Bill.java new file mode 100644 index 0000000..be4406c --- /dev/null +++ b/src/main/java/com/muyu/domain/Bill.java @@ -0,0 +1,21 @@ +package com.muyu.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +/** + * @Author: WangXin + * @date: 2024/7/26 + * @Description: + * @Version 1.0.0 + */ +@Data +public class Bill { + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date billDate; + private Double billMonery; +} diff --git a/src/main/java/com/muyu/mapper/BillMapper.java b/src/main/java/com/muyu/mapper/BillMapper.java new file mode 100644 index 0000000..ca3809b --- /dev/null +++ b/src/main/java/com/muyu/mapper/BillMapper.java @@ -0,0 +1,20 @@ +package com.muyu.mapper; + +import com.muyu.domain.Bill; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * @Author: WangXin + * @date: 2024/7/26 + * @Description: + * @Version 1.0.0 + */ +@Mapper +public interface BillMapper { + + List findAll(); + + int add(Bill bill); +} diff --git a/src/main/java/com/muyu/service/BillService.java b/src/main/java/com/muyu/service/BillService.java new file mode 100644 index 0000000..c8f0566 --- /dev/null +++ b/src/main/java/com/muyu/service/BillService.java @@ -0,0 +1,17 @@ +package com.muyu.service; + +import com.muyu.domain.Bill; + +import java.util.List; + +/** + * @Author: WangXin + * @date: 2024/7/26 + * @Description: + * @Version 1.0.0 + */ +public interface BillService { + List findAll(); + + int add(Bill bill); +} diff --git a/src/main/java/com/muyu/service/impl/BillServiceImpl.java b/src/main/java/com/muyu/service/impl/BillServiceImpl.java new file mode 100644 index 0000000..ef322bc --- /dev/null +++ b/src/main/java/com/muyu/service/impl/BillServiceImpl.java @@ -0,0 +1,33 @@ +package com.muyu.service.impl; + + +import com.muyu.domain.Bill; +import com.muyu.mapper.BillMapper; +import com.muyu.service.BillService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Collections; +import java.util.List; + +/** + * @Author: WangXin + * @date: 2024/7/26 + * @Description: + * @Version 1.0.0 + */ +@Service +public class BillServiceImpl implements BillService { + @Resource + private BillMapper billMapper; + + @Override + public List findAll() { + return billMapper.findAll(); + } + + @Override + public int add(Bill bill) { + return billMapper.add(bill); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..e484f21 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,27 @@ +# 应用服务 WEB 访问端口号 +server.port=8080 + +# 下面这些内容是为了让MyBatis映射 +# 指定Mybatis的Mapper文件 +mybatis.mapper-locations=classpath:mapper/*.xml +# 指定Mybatis的实体目录 +#mybatis.type-aliases-package=com.bw.bean +# 日志输出 +logging.level.com.bw=debug +# mybatis下划线转小驼峰 +mybatis.configuration.map-underscore-to-camel-case=true +# 数据库驱动: +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +# 数据源名称 +#spring.datasource.name=defaultDataSource +# 数据库连接地址 +spring.datasource.url=jdbc:mysql://127.0.0.1:3307/rik08?serverTimezone=UTC&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false +# 数据库用户名&密码: +spring.datasource.username=root +spring.datasource.password=wx0713101x +#连接数据库使用SQL方言 +#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +#自动创建表和更新表结构 +#spring.jpa.hibernate.ddl-auto=update + + diff --git a/src/main/resources/mapper/BillMapper.xml b/src/main/resources/mapper/BillMapper.xml new file mode 100644 index 0000000..1ec9853 --- /dev/null +++ b/src/main/resources/mapper/BillMapper.xml @@ -0,0 +1,17 @@ + + + + + INSERT INTO `rik08`.`bill` + (`billDate`, `billMonery`) + VALUES + ( #{billDate},#{billMonery}); + + + + +