第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Java Spring Boot 項(xiàng)目中的存儲(chǔ)過(guò)程返回 null 作為輸出

Java Spring Boot 項(xiàng)目中的存儲(chǔ)過(guò)程返回 null 作為輸出

Qyouu 2023-06-08 14:14:17
我在 Spring Boot 項(xiàng)目中使用存儲(chǔ)過(guò)程并嘗試獲取輸出值,但在我的項(xiàng)目中它總是返回 null。但是,如果我通過(guò) HeidiSQL 調(diào)用該過(guò)程,它會(huì)起作用并為我提供正確的值。所以它必須用我的java代碼做一些事情。我調(diào)試了受影響的方法,但找不到返回 null 的原因。我已經(jīng)嘗試查找其他帖子,但找不到與我的特定問(wèn)題相匹配的內(nèi)容。這是我嘗試使用存儲(chǔ)過(guò)程的方法:公司資源服務(wù)實(shí)現(xiàn)@Servicepublic class CompanyResourceServiceImpl implements CompanyResourceService {@PersistenceContext    private EntityManager entityManager;...private int getMetalResourceByPlayerId(int theId) {        StoredProcedureQuery theQuery = entityManager.createStoredProcedureQuery("getAllMetalFromCompaniesByPlayerId");        theQuery.registerStoredProcedureParameter(1, Integer.class, ParameterMode.IN);        theQuery.registerStoredProcedureParameter(2, BigDecimal.class, ParameterMode.OUT);        theQuery.setParameter(1, theId);        theQuery.execute();        BigDecimal outAmount = (BigDecimal) theQuery.getOutputParameterValue(2);        return outAmount.intValue();    }...}以下是存儲(chǔ)過(guò)程:getAllMetalFromCompaniesByPlayerIdCREATE DEFINER=`root`@`localhost` PROCEDURE `getAllMetalFromCompaniesByPlayerId`(    IN `playerId` INT,    OUT `metalSum` DECIMAL(19,2))LANGUAGE SQLNOT DETERMINISTICCONTAINS SQLSQL SECURITY DEFINERCOMMENT ''BEGINSELECT sum(cr.amount) as metalSumFROM company_resource crJOIN company c ON (c.id = cr.company_id) WHERE c.player_id = playerId and cr.resource_id = 1;END我的目標(biāo)是獲取輸出值并在@Scheduled方法中使用它。正如我所說(shuō),在 HeidiSQL 中,存儲(chǔ)過(guò)程有效。
查看完整描述

1 回答

?
躍然一笑

TA貢獻(xiàn)1826條經(jīng)驗(yàn) 獲得超6個(gè)贊

經(jīng)過(guò)幾個(gè)小時(shí)的嘗試,我找到了一種讓它工作的方法。


首先我添加@NamedStoredProcedureQuery到我的CompanyResource實(shí)體類(lèi):


CompanyResource.java


@Entity

@Table(name = "company_resource")

@NamedStoredProcedureQueries({

        @NamedStoredProcedureQuery(name = "getAllMetalFromCompaniesByPlayerId",

                                    procedureName = "getAllMetalFromCompaniesByPlayerId",

                                    parameters = {

                                        @StoredProcedureParameter(mode = ParameterMode.IN, name = "playerId", type = Integer.class),

                                        @StoredProcedureParameter(mode = ParameterMode.OUT, name = "metalSum", type = BigDecimal.class)

                                    })

})

@IdClass(CompanyResourcePK.class)

public class CompanyResource {

...

}

然后我改變了我的getMetalResourceByPlayerId()方法CompanyResourceServiceImpl如下:


CompanyResourceServiceImpl.java


@Service

public class CompanyResourceServiceImpl implements CompanyResourceService {


@PersistenceContext

    private EntityManager entityManager;


...


private int getMetalResourceByPlayerId(int theId) {


        StoredProcedureQuery theQuery = entityManager.createNamedStoredProcedureQuery("getAllMetalFromCompaniesByPlayerId");


        theQuery.setParameter("Param1", theId);


        BigDecimal outAmount = (BigDecimal) theQuery.getSingleResult();


        return  outAmount.intValue();

    }


...


}


查看完整回答
反對(duì) 回復(fù) 2023-06-08
  • 1 回答
  • 0 關(guān)注
  • 213 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)