我想保存我的json數據對象到我的Postgresql使用jQuery(ajax調用發佈請求)和Java後單擊提交按鈕,請幫我做到這一點?提前致謝。如何使用jQuery Post和Java在PostgreSQL中保存json數據?
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數據庫。 – Nag
@Thomas關於具有java後端的JavaScript前端沒有什麼不明之處。其實這很常見。 – Kayaman