Reputation: 337
I tried this code below...can anyone kindly help me how to pass the params to the spring method and is it a correct implementation in angularjs.
@GetMapping("/extended-registered-time")
public ResponseEntity<List<Registered_time>> getSubLeaves(@ApiParam Pageable pageable) {
log.debug("REST request to get registered time : {}", pageable);
LocalDate startDate = LocalDate.of(2018,01,15);
LocalDate endDate = LocalDate.of(2018,01,24);
List<Registered_time> result = ExtendedRegisteredTimeService.
getSelectedRegisteredTime(startDate,endDate);
return new ResponseEntity<>(result, HttpStatus.OK);
}
This is the frontend implementation(AngularJs)
.factory('RegisteredTimeService', RegisteredTimeService);
RegisteredTimeService.$inject = ['$resource'];
function RegisteredTimeService ($resource) {
var userName="HGajanayake";
var resourceUrl = '/api/extended-registered-time/{'+userName+'}';
return $resource(resourceUrl, {}, {
'query': {
method: 'GET',
isArray: true
},
'status':{
method:"POST",
isArray:true,
Upvotes: 0
Views: 76
Reputation: 337
I couldnt get over with @requestParams so I choosed @pathVariable instead.I got the correct result.
This is my Service
function RegisteredTimeService ($resource) {
var userName="HGajanayake";
// var resourceUrl = '/api/extended-registered-time?employee='+userName;
var resourceUrl = "/api/extended-registered-time/:employee";
return $resource(resourceUrl, {}, {
'query': {
method: 'GET',
isArray: true
},
This is my api endpoint
@GetMapping("/extended-registered-time/{employee}")
@ResponseBody
public ResponseEntity<List<Registered_time>> getSubLeaves(@PathVariable String employee) {
List<Registered_time> result = ExtendedRegisteredTimeService.getSelectedRegisteredTime(employee);
return new ResponseEntity<>(result, HttpStatus.OK);
}
This is the controller where I call the service
function RegisteredTimeController ($rootScope, $scope, $state, Employee, RegisteredTimeService,Profile,$resource) {
var firstName="HGajanayake";
var c=RegisteredTimeService.query({employee:firstName},function(result) {
var v=result;
console.log(v);
});
Upvotes: 1