# spb **Repository Path**: accounting14/spb ## Basic Information - **Project Name**: spb - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-07-19 - **Last Updated**: 2021-07-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 工程简介 ## 快速上手 - Eclipse Version: 2021-03 (4.19.0) - Java Version:1.8 1. 安装 Eclipse 2. [设置镜像](https://backmountaindevil.github.io/post/eclipse-mirror/) 3. 通过 Eclipse 安装 Spring Tools 4 Eclipse -> Help -> MarketPlace:搜索 spring, 安装 Spring Tools 4 4. 下载代码,打开它,右键项目 -> Maven -> Update Project,这需要点时间 5. 设置数据库,src/main/resources/application.properties 一般来说修改数据库名称、用户名、密码即可,需要自己建库,不需要建表,程序会自己建表 ```bash # 建库案例 mysql -u root -p > create database db_example; # kearney 修改为你的用户名,password 修改为你需要的密码 > create user 'kearney'@'%' identified by 'password'; > grant all on db_example.* to 'kearney'@'localhost'; > flush privileges; > \q ``` 6. 右键项目 -> Run As -> Spring Boot app,访问 http://localhost:8080,有点东西说明跑起来了
带注释建表 sql spring boot 自动生成的表没有注释,特地写了一个带注释的sql ```sql CREATE TABLE `accounting14_cash` ( `id` int(11) NOT NULL COMMENT '收款明细单编号', `costid` int(11) DEFAULT NULL COMMENT '成本表单编号-外键', `taxid` int(11) DEFAULT NULL COMMENT '税务表单编号-外键', `fee` float DEFAULT NULL COMMENT '应收金额', `money` float DEFAULT NULL COMMENT '实收金额', `cashid` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '银行流水号', `account_from` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '付款银行账户', `account_to` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '收款银行账户', `note` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '交易备注', `staff` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '经手人', `status` int(11) DEFAULT NULL COMMENT '状态', `cost` float DEFAULT NULL COMMENT '成本金额', `tax` float DEFAULT NULL COMMENT '税费金额', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='核算 - 收款明细表 易' CREATE TABLE `accounting14_account` ( `account` varchar(100) COLLATE utf8_bin NOT NULL COMMENT '银行账户', `sum` float NOT NULL DEFAULT 0 COMMENT '余额', `note` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '备注' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='核算 -公司银行账户表 易' ```
## 添加用户 用 curl 发送 post 请求 ```bash curl localhost:8080/Accounting14/cash/add -d costid=100 -d taxid=201 -d fee=992.9 ``` - [curl 的用法指南](https://www.ruanyifeng.com/blog/2019/09/curl-reference.html) > -d 参数用于发送 POST 请求的数据体。 ## 查询用户 ```bash curl 'localhost:8080/api/all' ``` - [Spring Data JPA根据属性名查询,chengqiuming 2018-09-08](https://blog.csdn.net/chengqiuming/article/details/82528961) - []() ## Modole @Entity(name="accounting14_cash") - [ hibernate中@Entity和@Table的区别](https://www.cnblogs.com/softidea/p/6216722.html) > @Entity说明这个class是实体类,并且使用默认的orm规则,即class名即数据库表中表名,class字段名即表中的字段名 如果想改变这种默认的orm规则,就要使用@Table来改变class名与数据库中表名的映射规则 - [@Entity @Table注解. 徐海兴 2018-09-09](https://blog.csdn.net/u012326462/article/details/82558623):源码和实际都表示上面说的不对劲 ### 模板传参 ```html th:text="${name}" 给标签加入内容 th:value=${id} 给标签添加 value ``` - [spring boot用ModelAndView向Thymeleaf模板传参数](https://www.cnblogs.com/JavaArchitect/p/14424198.html) > 通过th:text="${name}"的形式,指定了存放${name}参数的占位符 为了要使用thymeleaf视图,必须要配置 `` - [Spring Boot & thymeleaf模板 使用 th:each 遍历对象数组 -生成一批html标签体](https://www.cnblogs.com/zhazhaacmer/p/10432527.html) - [关于Could not parse as expression的报错. 小异常 2020-07-14](https://blog.csdn.net/sun8112133/article/details/107339009):添加 layui 的表格 table 会发生这个异常 > 原来是 [[]] 这个内联表达式搞的鬼呀,于是我在 script 标签中添加了 th:inline=none 属性,禁用了此处的内联表达式,重新启动服务,大功告成! - [thymeleaf通过th:text设置input的值无法取到问题. 没忄没肺 2019-01-27](https://blog.csdn.net/qq_32131937/article/details/86671132) > ``` > > >``` - [thymeleaf---前后台传递对象集合---页面传参---转发和重定向---翻页功能---查看修改删除---下拉框. 李府二公子 2019-09-24](https://blog.csdn.net/C_N_D_N_/article/details/101306471) - [SpringBoot 数据库增删改查实例. Tobefrank 2017-10-19](https://blog.csdn.net/sz457763638/article/details/78283715#t10) ## 错误处理 - 404: http://localhost:8080/api/test/test - 500: http://localhost:8080/api/test - [Spring Boot 全局异常处理整理!开发必会!](https://zhuanlan.zhihu.com/p/91024424) ## Route * [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) - http://localhost:8080/ : src/main/resources/static/index.html - http://localhost:8080/Accounting14/cash/index :src/main/resources/templates/index.html 返回上一个页面,下面是 falsk 中模板里的写法,返回上一个页面(如果存在的话) ```javascript // 返回主页 function cancel() { window.location.href = "{{request.referrer or url_for('admin_key_set')}}"; } ``` - [Get Referer URL in Spring MVC. 2011](https://stackoverflow.com/questions/5588907/get-referer-url-in-spring-mvc) - [给Spring MVC增加一个referer View. steven_cheng 2008-12-24](https://blog.csdn.net/steven_cheng/article/details/83327415) ### static * [Where to put static files such as CSS in a spring-boot project? 2015](https://stackoverflow.com/questions/27170772/where-to-put-static-files-such-as-css-in-a-spring-boot-project) > Anywhere beneath src/main/resources/static is an appropriate place for static content such as CSS, JavaScript, and images. The static directory is served from /. For example, src/main/resources/static/signin.css will be served from /signin.css whereas src/main/resources/static/css/signin.css will be served from /css/signin.css. 静态资源放在 /static 中,模板中的对于静态资源的路径都是 / 打头 # API ## 成本表 - http://localhost:8080/api/cash/add?costid=22&&cost=520.14 参数: costid - 成本表的订单 id cost - 该订单对应的成本(金额) 根据成本表的 id 创建新的收款凭证 如果已经创建过,则不再创建,返回 false。 如果根据costid查询到的金额不一致,则返回 `error: 订单 id 对应的金额不等,请仔细检查` 如果确定是新的成本表,则创建并返回包含新收款凭证id的数据, 如 `{'code':0,'msg':'','count':1,'data':[{'id':'11'}]}` ## 账户表 - http://localhost:8080/api/acc/add?account=anidea&&sum=520.14 参数: account: string 账户名称(账户号) sum: float 金额、余额 添加 account 数据,添加失败时(已存在对应账户)失败返回 false, 成功创建新账户时返回true ## 税务表 - http://localhost:8080/api/cash/update/tax?costid=22&&taxid=52&&tax=13.14 参数: costid - 成本表的订单 id taxid - 该订单对应的税费表id tax - 税费 根据成本表的 id 更新收款凭证中的税费单号、税费。更新失败返回 false。更新成功返回 true。 更新缴费清单中关于税费的两项设置 # One Piece ## 改进建议 1. 数据库中金额全部采用 deciaml 的数据类型,其它组员也应如此 2. 关于颜色,整体界面采用黑色显得过于压抑,可以 bing 搜索下管理界面看看友好的的颜色配比 3. 关于必填项的颜色,可以在左侧文字提示必填项,输入框采用正常颜色 4. 登陆部分,在一些特定系统中是公开开放注册入口的,只允许后台管理录入新用户,比如教务系统、公司系统。 5. 督促组员使用版本控制系统进行代码发布 6. 展示列表加入分页,大量数据一直滚动太长 7. 如果不同选项都是对统一张表的不同类别进行展示,左侧分栏可以减少,在右侧加入筛选功能 8. 监督自己和组员的工作 ## 效果预览 ![管理员查看所有订单](./img/admin.jpg) ![管理员编辑订单](./img/adminall.jpg) # 延伸阅读 * [Accessing data with MySQL](https://spring.io/guides/gs/accessing-data-mysql/) * [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)