我是 Liftweb 的新手。我想使用 Lift Mapper 在 Mysql 数据库中存储 Json 文件
我的 Json 文件如下:-
[
{
"name": "Root Category",
"Id": "1",
"dispName": "",
"childs": [
{
"name": "Sub Category",
"Id": "",
"dispName": "",
"childs": [
{
"name": "Spec1",
"Id": "",
"dispName": "",
"childs": []
}
]
}
]
},
{
"name": "Root Category",
"Id": "",
"dispName": "",
"childs": [
{
"name": "Sub Category",
"Id": "",
"dispName": "",
"childs": [
{
"name": "Spec1",
"Id": "",
"dispName": "",
"childs": []
}
]
}
]
}
]
是否可以在 Lift Mapper 中存储 Json 文件。请给我建议。如果有人提供任何样本那就太好了
最诚挚的问候
GSY
最佳答案
目前 MySQL 还没有很好的支持存储 JSON。我的意思是它不会提供 MongoDB 提供的功能。不过,如果您愿意,社区提供了一些 JSON 处理功能。鉴于您可以将其存储在 VARCHAR
中。 TEXT
或 BLOB
字段类型为简单文本。这是一个映射器示例:
import net.liftweb.mapper._
import net.liftweb.common._
class SomeDbClass extends LongKeyedMapper[SomeDbClass] with IdPK {
def getSingleton = SomeDbClass
// set limit of chars - can be used in `validate()`
object quota_type extends MappedString(this, 1024)
}
object SomeDbClass extends SomeDbClass with LongKeyedMetaMapper[SomeDbClass]
对于我的一个项目,我将 JSON 作为字符串存储在 Postgres 中,因为我只需要读取和写入它,而无需在数据库中解析它并按字段查询。每当我需要具有查询和更新支持的高效 JSON 存储时,我都会使用 MongoDB 和 Record +(Casbah 或 Rogue)。
关于mysql - 如何在 MySql 中使用 Lift Mapper 存储 Json 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21350860/