mysql函数
CREATE DEFINER=`root`@`%` PROCEDURE `part_id_dpt`(
IN f_type INT,
in sys_name varchar(50),
#in f_length int,
out sy_content varchar(50)
)
BEGIN
declare res varchar(500);
declare tmp_content varchar(500);
declare temp_int int;
declare temp_date varchar(10);
declare now_date varchar(10);
if f_type =4 then -- 格式为 20990101000001
select system_content INTO tmp_content from code_system where system_name=sys_name;
if length(tmp_content) <>4 then
set tmp_content = '0001';
end if;
select CONVERT(tmp_content,UNSIGNED) into temp_int; -- 流水号
set res =LPAD(temp_int+1,4,0); -- 不足6位补0
END IF;
#SET res = '123';
#SELECT sy_content;
#SELECT res;
UPDATE code_system SET system_content =res WHERE system_name=sys_name;
select system_content INTO sy_content from code_system where system_name=sys_name;
END
mapper
//mybatis的xml必须有 sql语句不用写在里面
public interface OnDevMapper extends BaseMapper<OnDev> {
@Select("{CALL part_id_dpt(#{f_type,mode=IN,jdbcType=INTEGER }," +
"#{sys_name,mode=IN,jdbcType=VARCHAR }," +
" #{sy_content,mode=OUT,jdbcType=VARCHAR })}")
@Options(statementType = StatementType.CALLABLE)
void getNewId(Map<String, Object> map);
Sevice
put时sy_content是空,get时就会获取到值
Map<String, Object> params = new HashMap<String, Object>();
params.put("f_type", 4);
params.put("sy_content", "");
params.put("sys_name", "on_part_id");
onDevMapper.getNewId(params);
onDev.setPartId(params.get("sy_content").toString());