如何获取存储过程中插入的当前对象的属性?

时间:2018-11-27 04:34:19

标签: java database oracle jdbc spring-jdbc

在我的控制器上,我将对象Letter插入 TBL_LETTER 中,该对象具有存储过程 PCPR_ADD_LETTER 。因此,我需要当前对象 Letter 的属性。 >正在立即保存,但我无法获取它。

我正在通过api后映射:

@PostMapping("saveProcessAnexOne")
    public ResponseEntity saveAnnexOne(@RequestBody ProcessAnexOne processAnexOne) {
     Letter letter=new Letter(processAnexOne.getLetter().getLetterId(),
             processAnexOne.getLetter().getInout(),processAnexOne.getLetter().getInoutNo(),processAnexOne.getLetter().getInoutDate(),null,null,null,null,processAnexOne.getLetter().getSelectionId(),processAnexOne.getLetter().getAssessmentNo(),"PCS",null);      

     BigDecimal letterNo=letterService.insertLetter(letter);
     System.out.println("letterNo from db is"+letterNo);
}

在此声明中, System.out.println(“ db的letterNo为” + letterNo); 我需要在表中插入当前的letterNo。

LetterService.java

public interface LetterService {
        public BigDecimal insertLetter(Letter letter);

}

LetterServiceImpl.kava

@Service
public class LetterServiceImpl implements LetterService {

    @Autowired
    private LetterDao letterDao;

    @Override
    public BigDecimal insertLetter(Letter letter) {
        BigDecimal letter1=letterDao.saveLetter(letter);
        return letter1;
    }


    }

LetterDao.java

public interface LetterDao {
   public BigDecimal saveLetter(Letter letter);

}

LetterDaoImpl.java

@Override
    public BigDecimal saveLetter(Letter letter) {
        System.out.println("hitted here");
        SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate).withProcedureName("PCPR_ADD_LETTER");
        Map<String, Object> inParamMap = new HashMap<String, Object>();
        System.out.println(letter.getLetterId());
        /*inParamMap.put("p_LETTER_NO",1);*/
        inParamMap.put("p_LETTER_ID",letter.getLetterId());
        inParamMap.put("p_INOUT",letter.getInout());
        inParamMap.put("p_INOUT_NO",letter.getInoutNo());
        inParamMap.put("p_INOUT_DATE",letter.getInoutDate());
        inParamMap.put("p_LETTER_ISSUED_SUB_BY",letter.getLetterIssuedSubBy());
        inParamMap.put("p_LETTER_FILE",letter.getLetterFile());
        inParamMap.put("p_REPRESENTATIVE_NAME",letter.getRepresentativeName());
        inParamMap.put("p_REPRESENTATIVE_NAME_ENG",letter.getRepresentativeNameEng());
        inParamMap.put("p_SELECTION_ID",letter.getSelectionId());
        inParamMap.put("p_ASSESSMENT_NO",1);
        inParamMap.put("p_ENTRY_BY", letter.getEntryBy());
        inParamMap.put("p_R_STATUS",null);

        SqlParameterSource in = new MapSqlParameterSource(inParamMap);
        return (BigDecimal) simpleJdbcCall.execute(in).get("p_LETTER_NO");

    }

我插入字母并接收字母No的过程是:

CREATE OR REPLACE PROCEDURE PCA_OWNER.PCPR_ADD_LETTER
(
      p_LETTER_NO    IN OUT     TBL_LETTER.LETTER_NO%TYPE,
      p_LETTER_ID               TBL_LETTER.LETTER_ID%TYPE,
      p_INOUT                   TBL_LETTER.INOUT%TYPE,
      p_INOUT_NO                TBL_LETTER.INOUT_NO%TYPE,
      p_INOUT_DATE              TBL_LETTER.INOUT_DATE%TYPE,
      p_LETTER_ISSUED_SUB_BY    TBL_LETTER.LETTER_ISSUED_SUB_BY%TYPE,
      p_LETTER_FILE             TBL_LETTER.LETTER_FILE%TYPE,
      p_REPRESENTATIVE_NAME     TBL_LETTER.REPRESENTATIVE_NAME%TYPE,
      p_REPRESENTATIVE_NAME_ENG TBL_LETTER.REPRESENTATIVE_NAME_ENG%TYPE,
      p_SELECTION_ID            TBL_LETTER.SELECTION_ID%TYPE,
      p_ASSESSMENT_NO           TBL_LETTER.ASSESSMENT_NO%TYPE,
      p_ENTRY_BY                TBL_LETTER.ENTRY_BY%TYPE,
      --P_ENTRY_DATE              TBL_LETTER.ENTRY_DATE%TYPE,      
      p_R_STATUS                TBL_LETTER.R_STATUS %TYPE
  )
  IS
    BEGIN
        PPK_TRANS.INS_UP_LETTER('INS',
                                 p_LETTER_NO,
                                 p_LETTER_ID,
                                 P_INOUT,
                                 P_INOUT_NO,
                                 P_INOUT_DATE,
                                 P_LETTER_ISSUED_SUB_BY,
                                 P_LETTER_FILE,
                                 P_REPRESENTATIVE_NAME,
                                 P_REPRESENTATIVE_NAME_ENG,
                                 P_SELECTION_ID,
                                 P_ASSESSMENT_NO,
                                 P_ENTRY_BY ,
                                 NULL ,
                                 P_R_STATUS 
                              );
     END;
/

Letter.java是

public class Letter {

        private BigDecimal letterNo;
        private int letterId;
        private String inout;
        private String inoutNo;
        private String inoutDate;
        private String letterIssuedSubBy;
        private String letterFile;
        private String representativeName;
        private String representativeNameEng;
        private int selectionId;
        private int assessmentNo;
        private String entryBy;
        private String rStatus;

        public Letter() {
//i omitted other getters and setters           
        }

我的程序有什么问题吗?

我收到如下错误:

  

2018年11月27日上午10:15:45   org.springframework.jdbc.core.metadata.CallMetaDataContext   matchInParameterValuesWithCallParameters警告:无法找到   参数中“ P_LETTER_NO”的对应参数值   提供的值:[p_ASSESSMENT_NO,p_LETTER_FILE,p_SELECTION_ID,   p_R_STATUS,p_INOUT_NO,p_INOUT_DATE,p_ENTRY_BY,p_LETTER_ID,   p_INOUT,p_REPRESENTATIVE_NAME,p_REPRESENTATIVE_NAME_ENG,   p_LETTER_ISSUED_SUB_BY]

     

db Noull中的字母No

0 个答案:

没有答案