gpt4 book ai didi

java - 如何在spring中附加从前端检索的请求参数?

转载 作者:行者123 更新时间:2023-12-02 11:41:33 25 4
gpt4 key购买 nike

我在下面尝试了这段代码...任何人都可以帮助我如何将参数传递给 spring 方法,它是 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);
}

这是前端实现(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,

最佳答案

我无法克服@requestParams,所以我选择了@pathVariable。我得到了正确的结果。

这是我的服务

  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
},

这是我的 API 端点

  @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);

}

这是我调用服务的 Controller

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);
});

关于java - 如何在spring中附加从前端检索的请求参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48515277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com