Ajax envoyer des données au contrôleur .Méthode utiliser ces données lorsque le bouton a cliqué.Mon metod a model.addatribute.Alert valeur nulle post .Why?model.addAttribute ne fonctionne pas avec jquery?
Mon contrôleur
@RequestMapping(value = "index",method =RequestMethod.POST)
@ResponseBody champ Liste publique (@RequestParam ("tNom") String name, @ RequestParam ("dName") Chaîne dname, modèle de modèle) { chaîne tn = nom; Chaîne dn = dname; Liste coname = new ArrayList <>(); try { Connexion mycon2 = DriverManager.getConnection ("jdbc: mysql: // localhost: 3306", "root", "1996"); DatabaseMetaData metaData2 = mycon2.getMetaData(); ResultSet res4 = métaData2.getColumns (dn, null, tn, "%"); coname = new ArrayList <>(); while (res4.next()) { String nom_colonne = res4.getString ("COLUMN_NAME"); coname.add (nom_colonne); }
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return coname;
}
Index 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 index 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 ce type de balisage '
Répondre
Essayez ceci:
Source
2017-10-14 07:44:21 juanlumn
Questions connexes