【发布时间】:2016-04-23 12:54:40
【问题描述】:
我想在单击提交按钮后使用 jQuery(发布请求上的 ajax 调用)和 Java 将我的 json 数据对象保存到我的 Postgresql 中,请帮我这样做?提前致谢。
html:
(function() {
var testValue;
testValue = {};
$('input[id=buttonId]').click(function() {
var name;
name = $(this).attr('name');
testValue[name] = $(this).val();
});
$('#submit').click(function() {
$('input[id=fileId]').each(function($i) {
var name;
name = $(this).attr('name');
testValue[name] = $(this).val();
});
console.log(JSON.stringify(testValue));//it gives the json data object, after clicking on Submit button`[ex: {"firstButton":"button1","secondButton":"button2","file":"test.txt"} ]`
});
})();
PostgreSQL 表:create table savedata(id integer primary key, content json);
凭证:
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/dbname"
db.default.user=test
db.default.password=test
html:
<input type='button' value='button1' class='button' id="buttonId" name='firstButton'/>
<input type='button' value='button2' class='button' id="buttonId" name='secondButton'/>
<input type='file' name='file' id="fileId" value='file upload'/>
<input type='submit' value='submit' id='submit'>
【问题讨论】:
-
感谢@Thomas 的回复,是的,前端可以是 Javascript/AngularJS/jQuery,后端可以是 Java/Scala 和 Postgresql 数据库。
-
@Thomas 带有 java 后端的 javascript 前端一点也不晦涩。事实上,这很常见。
标签: java jquery json ajax postgresql