【问题标题】:parameter lost when the function is called调用函数时参数丢失
【发布时间】:2021-03-06 09:17:36
【问题描述】:

我有一个奇怪的事情。 当我从我的服务调用一个函数时,该服务丢失了所有参数。 我不知道何时以及为什么。

调试说当他们进入类时有参数,然后什么都没有。 我在另一个服务中做了一个类似的功能,它可以工作。真的很奇怪。

看(调试打印):

cftimesheet.web.rest.AppUserResource 输入:getAllAppUsersByCompany() with argument[s] = [1, AppUserCriteria{}, Page request [number: 0, size 20, sort: undefined: DESC,id: ASC]]

c.f.timesheet.web.rest.AppUserResourceREST 请求按公司 ID 获取 AppUsers:1

c.f.timesheet.service.AppUserService 输入:findByCompany() with argument[s] = [1, Page request [number: 0, size 20, sort: undefined: DESC,id: ASC]]

c.f.timesheet.service.AppUserService : 请求通过公司 id 获取所有 AppUsers !!!!!!!!!!!!!!!!!!!!!问题 id 丢失

findByCompany() 中的异常,原因 = 'java.lang.IllegalArgumentException:org.hibernate.QueryException:无法解析属性:未定义:com.freemind.timesheet.domain.AppUser [从 com.freemind.timesheet 中选择 appUser .domain.AppUser appUser where appUser.id=?1 order by appUser.undefined desc, appUser.id asc]'

代码如下:

AppUserRessource:

@GetMapping("/app-users/company/{id}")//tayo
public ResponseEntity<List<AppUserDTO>> getAllAppUsersByCompany(@PathVariable Long id,Pageable pageable) {
    log.debug("REST request to get AppUsers by company id: {}", id);
    Page<AppUserDTO> page = appUserService.findByCompany(id,pageable);
    return ResponseEntity.ok().body(page.getContent());
}

应用用户服务

   public Page<AppUserDTO> findByCompany(Long id,Pageable pageable){//?
        log.debug("Request to get all AppUsers by company id", id);
        return  appUserRepository.findByCompany(id,pageable).map(appUserMapper::toDto);
    }

查询:

   @Query("select appUser from AppUser appUser where appUser.id=?1")
    Page<AppUser> findByCompany( Long id, Pageable pageable);

你有什么想法吗?

谢谢。

【问题讨论】:

    标签: java spring-boot jpa jhipster


    【解决方案1】:

    你的调试语句是错误的

    log.debug("Request to get all AppUsers by company id", id);
    

    应该是

    log.debug("Request to get all AppUsers by company id {}", id);
    

    错误信息说

    order by appUser.undefined desc, appUser.id asc
    

    所以问题是 order by 语句,其中未定义。看起来您的寻呼请求在客户端没有正确形成,这是您应该调查的。

    【讨论】:

    • 真的谢谢你。所以我的请求中的错误是另外一回事。
    • 你在客户端使用javascript吗?这可能是未定义的来源,当分页正在制定时。
    • 我正在使用 Angular。我看到了问题,但不知道如何解决。我有一个排序函数发送到后端 => [数字:0,大小 20,排序:未定义:DESC,internal_user_id:ASC]]。它知道 asc 的 id,但它不想要 desc。有函数 const result = [this.predicate + ',' + (this.ascending ? 'asc' : 'desc')]; if (this.predicate !== 'internal_user_id') { result.push('internal_user_id'); } 返回结果;
    • 你想按什么排序?
    • 按 id。我看到了错误,不是作为谓词的好字符串。现在它起作用了。谢谢! :)
    猜你喜欢
    • 1970-01-01
    • 2021-12-10
    • 1970-01-01
    • 1970-01-01
    • 2021-01-17
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多