I am new to AngularJS and Spring MVC. I am trying to call a REST service from AngularJS and validate the login credentials.
I am not sure if I am trying to pass the param in the right way to pass it to the Controller. Please can someone guide me if I am missing any
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);
});
}
});
Spring controller
@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);
}
Error : Required String parameter 'userName' is not present.
I need to pass the value of username and password to Spring controller. I am trying to use @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" />