【发布时间】:2016-04-28 01:43:46
【问题描述】:
我是 Scala 和 Play 的新手,现在学习了一天,我有一个 json 对象,我需要将它发送到我的 scala 控制器类并连接到数据库来存储。我不知道该怎么做?请帮我解决这个问题。
(function() {
var jvalue;
jvalue = {};
$('input[id=buttonId]').click(function() {
var name;
name = $(this).attr('name');
jvalue[name] = $(this).val();
});
$('#submit').click(function() {
$('input[id=fileId]').each(function($i) {
var name;
name = $(this).attr('name');
jvalue[name] = $(this).val();
});
console.log(JSON.stringify(jvalue));//I need to use jvalue object in scala class to store and connect with my database(how can I use or parse or route to scala to use)
});
})();
斯卡拉:
def addJson = Action(BodyParsers.parse.json) { implicit request =>
jsonForm.bindFromRequest.fold(
errors => BadRequest,
{
case (content) =>
Jsoncontent.insert(Jsoncontent(NotAssigned, content))
Redirect(routes.Application.index())
}
)
}
路线
POST /addJson @controllers.Application.addJson
【问题讨论】:
标签: jquery json scala playframework coffeescript