model.addAttribute不适用于jQuery?
问题描述:
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');
}
});
尝试这种情况:
<script type="text/javascript" th:inline="javascript">
/*<![CDATA[*/
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');
}
});
/*]]>*/
</script>
答
尝试这种情况:
<script type="text/javascript" th:inline="javascript">
/*<![CDATA[*/
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');
}
});
/*]]>*/
</script>
AFAIK这种标记的'
回答
尝试这种情况:
相关问题