见 开发规范
定义了接口的路径规则,接口的请求参数,接口的响应数据等规则
响应状态码:
200 OK 201 Created 204 No Content
请求地址:GET /v1/examples?pageIndex=0&pageSize=20&mapBean[username]=xxx
参数:(query) pageIndex pageSize <其他条件>
响应: 状态码:200 OK
{ "code": 0, "message": null, "data": { "pageIndex": 0, "pageSize": 20, "currentCount": 8, "totalCount": 96, "items": [ {实体对象}, …… ] } }
请求地址:GET /v1/examples/{id}
参数:(path) id
响应: 状态码:200 OK
{ "code": 0, "message": null, "data": { 实体对象 } }
请求地址:POST /v1/examples
requestBody:(application/json)
{ 新增请求的对象VO }
响应: 状态码:201 Created
{ "code": 0, "message": null, "data": { 新增成功的实体对象 } }
请求地址:PUT /v1/examples/{id} requestBody:(application/json)
{ 更新请求的对象VO }
响应: 状态码:200 OK
{ "code": 0, "message": null, "data": { 更新成功的实体对象 } }
请求地址:DELETE /v1/examples/{id}
参数:(path) id
响应: 状态码:200 OK
{ "code": 0, "message": null, "data": { } }
请求地址:GET /v1/examples/exist-code
参数:(query) code 必须 id 可选
响应: 状态码:200 OK
{ "code": 0, "message": null, "data": { "exist": true/false } }
响应状态码:
400 Bad Request 401 Unauthorized 403 Forbidden 404 Not Found 500 Internal Server Error
请求错误(校验类异常,数据格式错误等情况)
响应: 状态码:400 Bad Request
{ "code": -1, "message": "Bad Request", "error": 'Bad Request' }
spring security 的未认证的异常
响应: 状态码:401 Unauthorized
{ "code": -1, "message": "Unauthorized", "error": 'Unauthorized' }
{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}
响应: 状态码:403 Forbidden
{ "code": -1, "message": "Forbidden", "error": 'Forbidden' }
spring 框架异常,未找到
响应: 状态码:404 Not Found
{ "code": -1, "message": "Not Found", "error": 'Not Found' }
{"timestamp":1531211597530,"status":404,"error":"Not Found","message":"Not Found","path":"/uaa/api/user2"}
响应: 状态码:500 Internal Server Error
{ "code": -1, "message": "Code is null", "error": 'Code is null' }
网关熔断时,返回的错误码
响应: 状态码:502 Bad Gateway
{ "code": -1, "message": "Bad Gateway", "error": 'Bad Gateway' }
mvn clean package
修改 pom.xml
<properties> <start-class>com.supwisdom.insitute.Application</start-class> </properties> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
在须构建成 docker 镜像的项目中,添加 Dockerfile,并修改 pom.xml
参考示例:
Dockerfile
FROM harbor.supwisdom.com/institute/openjdk:8-jre-alpine ARG NAME ARG VERSION ARG JAR_FILE LABEL name=$NAME \ version=$VERSION ENV ENABLE_JMX_SSL=false ENV JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -Dspring.profiles.active=docker ENV SPRING_PROFILES_ACTIVE=docker COPY --chown=java-app:java-app target/${JAR_FILE} /home/java-app/lib/app.jar EXPOSE 8080
pom.xml
<build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <configuration> <skip>false</skip> </configuration> </plugin> </plugins> </build>
执行构建
mvn clean package dockerfile:build
若要推送到镜像服务器,须添加配置,并联系 harbor 管理员为您添加权限、创建项目等
<server> <id>harbor.supwisdom.com</id> <username>your harbor username</username> <password>your harbor password</password> </server>
mvn dockerfile:push
代码提交时,规范commit 描述信息的规范
Commit message 都包括三个部分:header,body 和 footer。
<type>(<scope>): #<issue-no-1>, #<issue-no-2>, <subject> <BLANK LINE> <body> <BLANK LINE> <footer>
Header 包括:
type
用于说明 commit 的类别,只允许使用下面7个标识。
Body 详细描述,可选
Footer 对 不兼容变动,关闭 等提交的描述,可选(保留、暂时不用)
提交示例:
feat: #14, 初始化项目结构
doc: #1, #2, 完善sa-api的设计、新增sec-engine的设计
chore: 整理开发说明 由于开发过程中,使用了 redis、kafka 等中间件服务,故需要事先安装相关服务 为了方便,考虑采用 docker-compose 来启动相关服务