mybatis-plus操作存储过程
/****** Object: StoredProcedure [dbo].[SP_GetDjLsh] Script Date: 2022/9/2 16:50:43 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SP_GetDjLsh]
(@DjName NVarChar(100)='',
@DjLsh Int Output)
AS
declare @LshMax int;
Update STDjLsh with(rowlock)
Set @LshMax=DjLsh=DjLsh+1
Where DjName=@DjName
if @@ROWCOUNT=0 BEGIN
Set @LshMax=2;
Insert Into STDjLsh(DjName,DjLsh)
Values(@DjName,@LshMax)
END
Set @DjLsh=@LshMax-1
return @DjLsh
public interface Xcpd02dxbzgdhMapper extends BaseMapper<Xcpd02dxbzgdh> {
@Select("{call SP_GetDjLsh(#{DjName,mode=IN,jdbcType=VARCHAR},#{DjLsh,mode=OUT,jdbcType=VARCHAR})}")
@Options(statementType = StatementType.CALLABLE)
void GetDjLsh(Map<String,String> params);
}
几个坑:
@Select
注解。mode=OUT,jdbcType=VARCHAR
。@Options(statementType = StatementType.CALLABLE)
注解。Map<String,String> params1 = new HashMap<>();
params1.put("DjName","XCPD02DXBZD");
params1.put("DjLsh","1");
mySocketMsgHandler.xcpd02dxbzgdhMapper.GetDjLsh(params1);
System.out.println(params1);
几个坑:
Map<String,String> params
传参,才能获取参数存储过程返回的参数。存储过程返回的参数并不是通过GetDjLsh
的返回值过得的,而是通过Map<String,String> params
获得。