我使用弹簧形式,在我的形式中我使用了angularjs。但是当通过angularjs发送请求时,我无法访问控制器中的表单值。
Angularjs代码
function submitController($scope, $http) {
alert("function called");
$scope.submit = function()
{
var formData = $('#formId').serialize();
$http.post('searchPatientResult', formData).success(function(data) {
$scope.user = data;
console.log($scope.user);
});
};
}
表格代码
<label class="col-sm-2 control-label">Patient Id</label>
<div class="col-sm-2"><form:input path="patientId" class="form-control" type="number" /></div>
<label class="col-sm-2 control-label">Name</label>
<div class="col-sm-2"><form:input path="name" class="form-control" type="text" /></div>
<label class="col-sm-2 control-label">Age</label>
<div class="col-sm-2"><form:input path="age" class="form-control" style="width:100px; float: left;" type="number" /><span style="line-height: 30px; padding-left: 10px;
">years</span></div>
</div>
<div class="col-sm-2 col-lg-offset-10"> <input class='btn btn-primary btn-block' type='button' value='Search' ng-click="submit()" /></div>
答案 0 :(得分:0)
您的角度代码必须正确,请尝试此
<label class="col-sm-2 control-label">Patient Id</label>
<div class="col-sm-2"><form:input path="patientId" class="form-control" data-ng-model="patient.id" type="number" /></div>
<label class="col-sm-2 control-label">Name</label>
<div class="col-sm-2"><form:input path="name" data-ng-model="patient.name" class="form-control" type="text" /></div>
<label class="col-sm-2 control-label">Age</label>
<div class="col-sm-2"><form:input path="age" data-ng-model="patient.age" class="form-control" style="width:100px; float: left;" type="number" /><span style="line-height: 30px; padding-left: 10px;
">years</span></div>
</div>
<div class="col-sm-2 col-lg-offset-10"> <input class='btn btn-primary btn-block' type='button' value='Search' ng-click="submit(patient)" /></div>
和控制器
$scope.submit = function(patientData)
{
$http.post('searchPatientResult', patientData).success(function(data) {
$scope.user = data;
console.log($scope.user);
});
};
你可以在控制器中访问它,如
public void saveUser(@RequestBody Map map){
final String name = map.get("name");
}