【发布时间】:2015-11-19 05:20:28
【问题描述】:
我是 AngularJS 和 Spring MVC 的新手。我正在尝试从 AngularJS 调用 REST 服务并验证登录凭据。
我不确定我是否试图以正确的方式传递参数以将其传递给控制器。如果我缺少任何东西,请有人指导我
Controller.js
var SupportSystems = angular.module('SupportSystems', [ 'ngResource' ]);
SupportSystems
.controller(
'LoginController',
function($scope, $resource) {
$scope.authenticate = function() {
var authenticateUser = $resource('http://localhost:8080/SupportSystems/SSystems/authenticateUser/:userName', {userName: '@userName'});
authenticateUser.save(function(data) {
alert("user->" + $scope.userName);
alert("pass->" + $scope.password);
});
}
});
弹簧控制器
@RequestMapping("/SSystems")
public class SupportSystemsController { `
@RequestMapping(value="/authenticateUser/{userName}", method=RequestMethod.POST)
public ResponseEntity<Boolean> authenticateUser(@RequestParam("userName") String userName) {
System.out.println("username -->" + userName);
return new ResponseEntity<Boolean>(Boolean.TRUE, HttpStatus.OK);
}
错误:必需的字符串参数“用户名”不存在。
我需要将用户名和密码的值传递给 Spring 控制器。我正在尝试使用@RequestParam
<body ng-controller="LoginController">
<form class="login-form" name="loginForm" ng-submit="authenticate()">
<h2> Login</h2>
<input type="text" id="userName" class="form-control" name="userName" required autofocus="autofocus"
ng-model="userName" />
【问题讨论】: