0
Ajax將數據發送給控制器。方法使用該按鈕點擊後的數據。我metod有model.addatribute.Alert後null值爲什麼?model.addAttribute不適用於jQuery?
我的控制器
@RequestMapping(value = "index",method =RequestMethod.POST)
@ResponseBody 公共列表字段(@RequestParam( 「TNAME」)字符串的名稱,@ RequestParam( 「DNAME」)字符串DNAME,型號model){ 字符串TN =名; String dn = dname; List coname = new ArrayList <>(); 嘗試連接mycon2 = DriverManager.getConnection(「jdbc:mysql:// localhost:3306」,「root」,「1996」); DatabaseMetaData metaData2 = mycon2.getMetaData(); ResultSet res4 = metaData2.getColumns(dn,null,tn,「%」); coname = new ArrayList <>(); (res4.next()){ String column_name = res4.getString(「COLUMN_NAME」); coname.add(column_name); }
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return coname;
}
指數HTML
<div id="RightPanel" style="width: 200; height: 100%; float: right;">
<table class="table table-striped">
<input type='text' id='tablehead' />
<tr>
<th>Column name</th>
</tr>
<tr th:each="name : ${cname}">
<td> th:text="${name}"</td>
</tr>
</table>
</div>
的JavaScript在索引HTML
<script th:inline="javascript">
function onclk(a,b) {
var search = {
"tName" : a,
"dName" :b
}
$.ajax({
type: "POST",
url: "http://localhost:8092/index",
data: search,
dataType: "json",
success: function (data) {
var modelAttributeValue = [[${coname}]];
alert(modelAttributeValue); },
error: function(){
alert('got error');
}
});
AFAIK這種標記的'
回答
嘗試這種情況:
來源
2017-10-14 07:44:21 juanlumn
相關問題