Closed wangzhenhui1991 closed 7 years ago
常用快捷键
https://github.com/judasn/IntelliJ-IDEA-Tutorial
文档:https://www.gitbook.com/book/huangwenchao/swagger/details
思维导图:http://openapi-specification-visual-documentation.apihandyman.io/
http://www.sosoapi.com/
源码分析
SosoApi项目采用jquery + bootstrap + jsp + springmvc + mybatis + mysql相关技术,结合maven进行项目管理。
http://www.ruanyifeng.com/blog/2014/05/restful_api.html
http://www.jianshu.com/p/e83d323c6bcc
https://www.zhihu.com/question/
http://www.cnblogs.com/sunniest/p/4555801.html
Maven intel集成目录 Setting C:\Users\wangzhenhui.m2\settings.xml .m2 C:\Users\wangzhenhui.m2\repository Maven wzh目录 D:\Java\Maven
P1: xml中新建XX-servlet.xml 不支持spring xml 解决:Intellij IDEA enable spring support https://www.jetbrains.com/help/idea/2016.2/enabling-spring-support.html#plugin
初步理解Tomcat https://github.com/pzxwhc/MineKnowContainer/issues/55 初步理解Servlet https://github.com/pzxwhc/MineKnowContainer/issues/32 初步理解FrameServlet https://github.com/pzxwhc/MineKnowContainer/issues/34 理解DispatcherServlet https://github.com/pzxwhc/MineKnowContainer/issues/35
SpringMVC Tutorial http://www.mkyong.com/tutorials/spring-mvc-tutorials/
Spring的IOC和AOP http://tracylihui.github.io/2015/07/28/spring/Spring%E7%9A%84IOC%E5%92%8CAOP/ IOC http://www.importnew.com/17609.html AOP http://blog.csdn.net/udbnny/article/details/5870076 http://www.cnblogs.com/powerdk/p/4150112.html http://wiki.jikexueyuan.com/project/spring/aop-with-spring-framenwork/aspectj-based-aop-with-spring.html http://skyfar666.iteye.com/blog/2008716
d) AOP支持
package inds.wzh.aop;
import org.aspectj.lang.annotation.*;
/**
* Created by wangzhenhui on 2016/11/22.
*/
//切面声明
@Aspect
public class AOPHelper {
public AOPHelper(){
}
//声明切入点
@Pointcut("execution(* index(..))")
public void pointcut(){}
//声明before通知
@Before("pointcut()")
public void doBeforeTask(){
System.out.println("before");
}
//声明after通知
@After("pointcut()")
public void doAfterTask(){
System.out.println("after");
}
// @AfterReturning(pointcut = "pointcut()", returning="retVal")
// public void doAfterReturnningTask(Object retVal){
// // you can intercept retVal here.
// System.out.println("afterRunning+RETURN:"+retVal);
// if(retVal==null) retVal="index";
//
// }
// @Around("pointcut()")
// public void doAroundTask(){
// System.out.println("Arround");
//
// }
}
下载:redis-release.exe 安装:
$> redis-server redis.windows.conf
运行:
$> redis-cli.exe
监听端口: 6379
$> npm install pm2@latest –g
Action | pm2 start | [scriptName] |
---|---|---|
pm2 stop | ||
pm2 start | ||
pm2 reload | ||
pm2 graceReload | ||
pm2 delete | ||
info | ||
pm2 log | ||
pm2 monit | ||
pm2 list | ||
pm2 show|describe | ||
pm2 flush | ||
pm2 reloadLogs |
port | 3000 | 配置pm2-Server监听端口 | |
---|---|---|---|
cwd | ”./mockbin” | 配置pm2-Server启动脚本的路径,配置到mockbin项目的根目录 | |
script | ”server.js” | 配置mockbin项目的启动文件名 | |
name | ”Server” | 设置服务的默认项目名 | |
watch | true | 设置pm2-Server是否开启watch模式,脚本发生改动,自动重启脚本 | Win下不绑定日志变动,linux下监听了服务的日志变动,导致无限重启 |
output | "./logs/out.log" | 输出日志 | |
error | "./logs/err.log" | 错误日志 | |
logDateFormat | "YYYY-MM-DD HH:mm Z" | 日志文件名的格式 | |
force | true | ||
max_memory_restart | “100M” | 重启内存阈值,达到100M,自动重启脚本 | |
node_args | (Script port jsonpath) | 配置node_args, | |
更多参考: |
所属类 | 请求URL | 处理函数(入口参数) | 核心逻辑 | 返回 | |
---|---|---|---|---|---|
class BuildMockerUtil | addPort(docId) | pm2ServerHost/start | return port; | ||
isRunningMock(docId) | pm2ServerHost/restart | return port; | |||
class SwaggerController | /apidoc/buildJson | docId=[],port=[] | buildJson(request,docId,port) | return swagger; | |
/auth/apidoc/json/build.json | docId=[],port=[] | buildApiDoc(request,docId,port) | return swagger; | ||
/auth/doc/inter/json/mockData.htm | docId=[],interId=[] | mockData(request,model,docId,interId) | get MockUrl | return “redirect:”+mockUrl |
Sosoapi | paramter | swagger API | sosoApi mockData | sosoApi SwaggerUI | pm2Server | Dhc | mockbin | ||
---|---|---|---|---|---|---|---|---|---|
get /main/pets | 1 | 1 | 1 | 1 | 1 | 1 | |||
id(string) in query | 1 | 1 | 1 | 1 | get /pet in query | 1 | |||
post /main/pet | name in formData | 1 | 1 | fromData | 1 | post /pet | 0 | Notice:将body-parser提前获取streamer事件,并且取消了dice.write(req.body)处理,因为这里重写了req.body,因为body-parser对于content-type=fromData,会额外写bounry和content-despition到req.body中 |
post为什么要额从Streamer中读取? | name in body | 1 | 0:errorbodyparamer无法修改属性 | 0:fromDatacurl->application/x-www-form-urlencoded0:error Operation:Post->Option | | | 0 | Notice:在swagger中定义了post /pet,并且 in :”body”,name:”name”,required:true,并没有String属性,所以在swagger校验中,swagger报出
Unexpected token n in JSON at position 1
问题:?在tuhuapi中定义的 body string 属性,并没有在swagger中生成。param-parser中param.schema=undefiend. | delete /main/pet/{id} | id in path | 1 | 0:error rediectUrl | 0:error Operation:Delete->Option | 1 | delete /pet/{id} | 1 | | | id in query | | | 0:error Operation:Delete->Option | | | | | | | | | | | | | | | | | | | | | | | put /main/pet | | | | 0:error Operation:Put->Option | | put /pet | 1 | | | in Header | | | | | | | | | in Cookie | | | | | | | | | | | | SwaggerUI默认先发送option请求 | | | | | | | | | | | | | | | | | | | | | | |3.关于parameter Object https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameterObject
i. path
ii. query
iii. header
iv. body
v. form
body
name: user
in: body
description: user to add to the system
required: true
schema:
$ref: '#/definitions/User'
name: user
in: body
description: user to add to the system
required: true
schema:
type: array
items:
type: string
header
name: token
in: header
description: token to be passed as a header
required: true
type: array
items:
type: integer
format: int64
collectionFormat: csv
path-/items/{itemId}
name: username
in: path
description: username to fetch
required: true
type: string
query-/items?id=###
name: id
in: query
description: ID of the object to fetch
required: false
type: array
items:
type: string
collectionFormat: multi
form
name: avatar
in: formData
description: The avatar of the user
required: true
type: file
get | /start | name=[],port=[],jsonpath=[] | pm2.connect() | pm2.start() | ||
get | /restart | name|port=[],jsonpath=[] | pm2.connect() | pm2.describe() | pm2.delete() | pm2.start() |
get | /delete | name=[] | pm2.connect() | pm2.delete(name) | ||
get | /deleteAll | pm2.delete(all) | ||||
get | /describe | name=[] | pm2.connect() | pm2.describe() | ||
get | /reload | |||||
get | /stop | |||||
get | /list |
请求URL | 处理文件 | Handler\ | MiddleWare | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Swagger Validate | MockBin | ||||||||||||||
Get | /create | path=[],method=[] | form.js | mw.forwarded | mw.body-parser | mw.cors | form.js | mw.negotiateContent | /views/bin/create.jade | ||||||
post | /create | postData | create.js | mw.forwarded | mw.body-parser | mw.cors | create.js | mw.negotiateContent | /views/redirect.jade | ||||||
get | /edit | path=[],method=[],index=[] | editbin.js | mw.forwarded | mw.body-parser | mw.cors | editbin.js | mw.negotiateContent | /vies/bin/edit.jade | ||||||
post | /edit | postData | updatebin.js | mw.forwarded | mw.body-parser | mw.cors | updatebin.js | mw.negotiateContent | /views/redirect.jade | ||||||
get | */view | view.js | mw.forwarded | mw.body-parser | mw.cors | view.js | mw.negotiateContent | /views/bin/view.jade | |||||||
get | */log | method=[],index=[] | log.js | mw.forwarded | mw.body-parser | mw.cors | log.js | mw.negotiateContent | /views/bin/log.jade | ||||||
get | */list | list.js | mw.forwarded | mw.body-parser | mw.cors | list.js | mw.negotiateContent | /view/bin/list.jade | |||||||
get | /paths | ajax_paths.js | mw.forwarded | mw.body-parser | mw.cors | ajax_paths | mw.negotiateContent | ||||||||
delete | /deletebin | path=[],method=[],index=[] | ajax_deletebin.js | mw.forwarded | mw.body-parser | mw.cors | ajax_deletebin | mw.negotiateContent | |||||||
post | /updatestatus | path=[],method=[],index=[] | ajax_updatestatus.js | mw.forwarded | mw.body-parser | mw.cors | ajax_updatestatus | mw.negotiateContent | |||||||
get | /log | path=[],method=[],index=[] | ajax_log.js | mw.forwarded | mw.body-parser | mw.cors | ajax_log.js | mw.negotiateContent | |||||||
get | /* | swagger.js | metadata() | files() | parseRequest | validateRequest | mw.swagger-body-parser | mw.cors | swagger.js | logHandler | errHandler |
mw.body-parser中有对req streamer流事件的监听,swagger.middleware中的parseRequest也有对req.streamer流事件的监听,所以相互之间只有一方能够捕获到事件,没有捕获的的middleware就会无法继续进行。 两者都对信息写到req.body中,我们将mw.swagger-body-parser放到后面,当mw.body-parser 解析request请求,将request对象中 我们需要的属性提取出来,放到req中。以便create.js ,updatebin.js和swagger.js使用。
大致步骤 | |||||
---|---|---|---|---|---|
1. | req.on(‘data’) | req.on(‘end’) | req.body | 后置处理 | |
2. | req.har = util.createHar(req); | swagger.js | swagger.js中需要req.har.log.entries[0]作为日志信息添加到redis中 | ||
3. | req.simple = util.createSimpleHar(req); | Postcreate.jsupdatebin.js | |||
4. | switch (req.contentType) | case 'application/json': | req.jsonBody = JSON.parse(req.body) | ||
case 'application/x-www-form-urlencoded': | req.formBody = querystring.parse(req.body);req.simple.postData.params = req.formBody; req.har.log.entries[0].request.postData.params = util.objectToArray(req.formBody); | ||||
case 'multipart/mixed': case 'multipart/related': case 'multipart/form-data': case 'multipart/alternate': | var dice = new Dicer(…)dice.on('part', function (part)dice.on('finish', function ()dice.write(req.body); |
docker Cli Cmd
docker pull IMAGE
docker run –v HOSTVOLUME:CONTAINERVOLUME
docker build
docker attach CONTAINER
docker ps
docker exec –it CONTAINER bash
Dockerfile reference: FROM MAINTAINER RUN COPY ADD CMD
Compose command-line reference:
alias dc=”docker-compose”
dc up –d
dc start | stop | restart CONTAINER
dc ps
dc logs –f
docker-compose.yaml
Compose file reference : https://docs.docker.com/compose/compose-file/ version services build ports volumes
1.intellij IDEA
常用快捷键
2.openAPI
文档 思维导图
3.sosoapi-web
4.RESTful API 设计指南
http://www.ruanyifeng.com/blog/2014/05/restful_api.html
5.http协议
http://www.jianshu.com/p/e83d323c6bcc
6.javabean
jquery + bootstrap + jsp + springmvc + mybatis + mysql
7.Spring MVC
http://www.cnblogs.com/sunniest/p/4555801.html
11-24
1.nodejs
2.swagger-express-middleware.sample2.js解析
1.模块声明
2.Data
3.Resource
4. metadata(router)
----app.use(middleware.metadata());----将*.yaml中的元素映射到对象中
5. files([router], [options])
6. parseRequest(router, options)
7. CORS(router)
8. mock(router)
3.swagger-parser 解析
1.mockbin
bins
2.redis
http://www.runoob.com/redis/redis-install.html
3.CURL 命令
http://www.ruanyifeng.com/blog/2011/09/curl.html
4.nodejs express req res
5.jade
4.
5. 关于javascript中apply()和call()方法的区别
call 和 apply 都是为了改变某个函数运行时的 context 即上下文而存在的,换句话说,就是为了改变函数体内部 this 的指向。 http://www.cnblogs.com/fighting_cp/archive/2010/09/20/1831844.html 理解:https://www.zhihu.com/question/20289071
6.JavaScript promise
http://www.alloyteam.com/2014/05/javascript-promise-mode/
7. nodejs redis api
https://redis.readthedocs.io/en/2.4/list.html#ltrim express 正则
creat.jade: div.col-sm-6 div.input-group span.input-group-addon Load File input(type='file').form-control
8. jade 引用变量
http://www.lellansin.com/jade-%E6%A8%A1%E6%9D%BF%E5%BC%95%E6%93%8E%E4%BD%BF%E7%94%A8.html
11-29
1. webstrom 代码格式化
express.app.use() 如何创建express项目 http://expressjs.com/zh-cn/starter/hello-world.html helloworld
express api
express 指南
swagger express middleware
lodash-JavaScript中的数据转换、匹配、查找
node.js path 返回上级目录 util
JavaScript concat() 方法
redis nodejs keys调用
11-30 js bind() call() apply() http://blog.jobbole.com/58032/ http://web.jobbole.com/83642/
dicer
Path-to-RegExp
colors
12-5
问题:
1.yaml 中一个路径对应多个Method,也就对应多个Response,怎么怎么做到一一对应?就是一个request通过了path,method,params校验,还有多个Response可以选择,我们应该返回哪一个?
2.key 改为 PATH+METHOD, 如何将Key转换成访问路径?
3./bin/{key:path}/view,增加编辑,删除,日志查看功能?
4./bins/查看所有bin ->keys path:*
5.当一个path与Swagger定义的basePath不匹配的时候,应该怎么定义这个路径?
6.req Post 对象无反应问题
node的streamer的data 和end 事件
7.req.on('data',function());
8.swagger consume produces
9.what is mean "resource path" or a "collection path"?
10.res.format(object)
12-6
1.key改为
2.js 回调函数
3.redis 事务调用
4.redis get 同步调用
12-7
1.Error: Can't set headers after they are sent.
2.
3. 开关问题
4.icon
12-8
1.更新 /path/list
2.jquery相关问题
jquery get td value
var index = $(this).parent().parent().parent().find('td:eq(2)').html();
jquery ajax param
jquery ajax jade table
jquery 选择器
总结一下 del功能 1.jquery找到标签 ,获取 标签id,读出[path,method,index] 发送jquery ajax请求 2.express route delete /deletebin?path=[]&method=[]&index=[] 执行操作并响应 3.ajax等待ajax Response,删除 将响应的标签 $(tr#data-id=id,tr#bin-id=id).remove() openStatus 0.修改 IndexKey---> Rename Path:[/path],Method:[Method],Index [Value] Path:[/path],Method:[Method],Count [Value] 1.get /path/list 2.listKey----->keys(Path:[path],Method:[],Index) ---->keys keys符合 Path:[path],Method:[],OpenIndex Path:[path],Method:[],Index: 3.mget(keys) ----> values
在对剩余values中遍历,对每个value进行JSON.parse(value),然后对该value与openData中的属性进行匹配,如果该value符合openData,设置value.active=true------ << O(N*4) ChangeOpenIndex
用到的知识: jquery选择器,jqueryTabel tr td getvalue,Jquery Ajax ,Jquery Param,css display:none。 js Array 和Json对象,遍历,string切割
12-9
1.jquery .toggleClass()
2.button bootstrap
3. div.form-group.pair
12-12
1.添加 slideBar
2. 添加 Log到
3. 整合 Edit到list
4. 增加 搜索---排序
5.问题 /view 内容调整
6.post body-parser无反应
7.修改访问路径----> host/bin/baseURL/swagger.path
8.总结一下:路由以及中间件
/ AJAX |delete |/deletebin? |deletebin.js | deletebin.js path & method & index
9. node Cnode -get start
https://cnodejs.org/getstart
10.npm config
2.PM2
3.node 打包
4.给slidebar 添加 dragbar
11.API - proj