Spring調用存儲過程

public Boolean bindCard(final BindCardProfile bindCardProfile) throws DataAccessException {
        if (bindCardProfile == null) {
            return false;
        }

        String dbReturn = jdbcTemplate.execute(new CallableStatementCreator() {

            @Override
            public CallableStatement createCallableStatement(Connection con) throws SQLException, DataAccessException {
                // TODO Auto-generated method stub
                String stroedProc = "CALL sp_bind_card(?, ?, ?, ?, ?, ?, ?)";
                CallableStatement callableStatement = con.prepareCall(stroedProc);
                callableStatement.setString("p_cellphone", bindCardProfile.getCellphone());
                callableStatement.setString("p_name", bindCardProfile.getName());
                callableStatement.setString("p_id_card", bindCardProfile.getIdCard());
                callableStatement.setString("p_bank_card_no", bindCardProfile.getBankCardNo());
                callableStatement.setString("p_channel_name", bindCardProfile.getChannelName());
                callableStatement.setString("p_bank_abbr", bindCardProfile.getBankAbbr());
                callableStatement.registerOutParameter("p_returnVal", Types.NVARCHAR);
                return callableStatement;
            }
        }, new CallableStatementCallback<String>() {
            public String doInCallableStatement(CallableStatement callableStatement)
                    throws SQLException, DataAccessException {
                callableStatement.execute();
                return callableStatement.getString("p_returnVal");
            }
        });

        return dbReturn.equals("success");
    }

1 在類中使用Spring管理對象時,同時又用Spring對象實例話另一個對象時,注意其位置,如下面的代碼,這樣定義時會Error,會出現空的指針,具體可能在初始化對象時,和Spring的先後順序有關

//@Repository
public class CacheKeyManager {

    @Resource(name="stringRedisTemplate")
    private RedisTemplate<String, String> redisTemplate;
    **RedisSerializer<String> stringSerializer=redisTemplate.getStringSerializer();**
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章