小编Sab*_*kya的帖子

Nx React - 代理无法与 Nx 和 React 一起使用

我有一个使用 Nx 创建的 React 应用程序,我试图对我的开发服务器进行 api 调用,但遇到了 CORS 问题。所以我尝试按照此链接设置代理:https://nx.dev/l/r/tutorial/06-proxy#react-nx-tutorial---step-6-proxy-configuration

在我的项目服务器中,我添加了:

工作空间.json 或项目.json

"serve": {
      "executor": "@nrwl/web:dev-server",
      "options": {
        "buildTarget": "my-app:build",
        "hmr": true,
        "proxyConfig": "apps/my-app/proxy.conf.json"
      },
Run Code Online (Sandbox Code Playgroud)

和 proxy.conf.json:

{
  "/my-context-path/api/v1": {
    "target": "https://my-dev-server.com",
    "secure": true
  }
}
Run Code Online (Sandbox Code Playgroud)

并将 api 调用设置为:

export async function getInfo(planId, nbr) {
   return  await fetch(`/my-context-path/api/v1/getInfo?planId=${planId}&nbr=${nbr}`, {
     method: 'GET',
     headers: {
       'Authorization': 'Basic authHeader',
       'Content-Type': 'text/plain',// adding or removing this header is making no difference
     }
   }).then(async (response) => {
      // success block
   }).catch(async (error) => { …
Run Code Online (Sandbox Code Playgroud)

proxy cors reactjs nrwl-nx

7
推荐指数
0
解决办法
5870
查看次数

JPQL 和 JPA 中的本机查询“GROUP_CONCAT”是否有替代方案?

我正在尝试使用 jpql 和 JPA 来获取配置文件的配置文件菜单。我的“个人资料”和“个人资料菜单”实体具有多对一的关系。

我尝试过研究这些答案,但找不到任何可行的解决方案。

如何在Spring Boot应用程序中添加非标准化sql函数?

使用 JPA 和 Hibernate 注册 SQL 函数

https://vladmihalcea.com/hibernate-sql-function-jpql-criteria-api-query/

我也浏览了这个链接,似乎和我有同样的问题, How to register non-standardized SQL function Manual in Spring Boot application?

使用本机查询时,我可以使用以下查询获取数据:

 SELECT
 GROUP_CONCAT(pm.user_menu_id SEPARATOR ',')
 AS profile_menu_ids,
 p.description
 FROM profile p
 LEFT JOIN profile_menu pm ON p.id = pm.profile_id
 WHERE
 p.id =:profileId
 AND
 pm.status = 'Y'
 GROUP BY p.id
Run Code Online (Sandbox Code Playgroud)

上述查询为我提供的数据为,

个人资料菜单 ID 描述
4,5 管理员简介

jpql 和 JPA 中是否有任何方法或替代方案来获得上述结果?

java mysql jpa jpql spring-boot

5
推荐指数
1
解决办法
5069
查看次数

Spring Boot 控制器的 catch 块的 JUnit5 测试覆盖率

我正在尝试使用以下代码为我的控制器编写测试。我想对 catch 块语句中的代码进行测试,但我无法编写。我想在 catch 块中返回一个带有失败代码和消息的服务器响应。

@PostMapping(COUNTERS)
public ResponseEntity<?> getCounters(@Valid @RequestBody ApartmentCounterListRequest requestData) {
    try {
        log.debug("Entering API for counter list");
        ApartmentCounterListResponse apartmentCounterListResponse = counterService.getAllCounters();
        return ResponseEntity.ok(apartmentCounterListResponse);
    } catch (Exception exception) {
        log.error("Exception in counter list :: ", exception);
        ServerResponse serverResponse = ResponseBuilder.buildVendorFailureMessage(new ServerResponse(),
                RequestResponseCode.EXCEPTION);
        return ResponseEntity.ok(JsonResponseBuilder.enquiryResponse(serverResponse));
    }
}
Run Code Online (Sandbox Code Playgroud)

我的测试代码如下:

@Test
@DisplayName("Should return ServerResponse with failure data.")
void Should_Return_Server_Response_On_Exception() throws Exception {

    /*given*/
    ApartmentCounterListRequest apartmentCounterListRequest = ApartmentTestUtil.getApartmentCounterListRequest.
            apply("test", "test");
    Mockito.when(counterServic.getAllCounters()).thenThrow(new Exception());
//        ServerResponse serverResponse = ApartmentTestUtil.getServerExceptionServerResponse.get();

    /*then*/
    mockMvc.perform(
            post(COUNTER_URL)
                    .contentType(APPLICATION_JSON)
                    .content(objectMapper.writeValueAsString(apartmentCounterListRequest))) …
Run Code Online (Sandbox Code Playgroud)

java unit-testing mockito spring-boot junit5

2
推荐指数
1
解决办法
105
查看次数

标签 统计

java ×2

spring-boot ×2

cors ×1

jpa ×1

jpql ×1

junit5 ×1

mockito ×1

mysql ×1

nrwl-nx ×1

proxy ×1

reactjs ×1

unit-testing ×1