LoopBack 操作记录 | Ohmer's Blog

JerryXia 发表于 , 阅读 (0)
Get Started

继续查看Getting started

自定义MySql连接

自定义table名字

在模型的json文件中common/model/category.json添加Mysql的配置

1
2
3
4
5
6
7
8
{
"name": "Category",
...
"mysql": {
"table": "custom_category" // 自定义的表名
}
...
}

更多Model的Json定义参考Model definition JSON file

自定义table列名

同样在模型定义的json文件中,common/model/category.json找到properties模块的配置,为需要自定义表列名的属性下添加msql配置信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"name": "category",
...
"properties": {
...
"title": {
"type": "String",
"required": true,
"mysql":{
"columnName":"question_content",
"dataType":"VARCHAR"
}
},
...
},
...
}

还有其他类型类型的对应关系,可以看MySQL connector

自定义请求方法(Remote Method)

loopback默认提供了许多方法,可以方便的访问到服务端的资源,这里列出一些常用的,更多的方法可以参考文档