Mybatis insert 작업은 증가된 주 키 id를 반환합니다.
2145 단어 SSM
mysql 데이터에 insert 아래에 되돌아오는 형식과 값을 지정하기 위해 selectKey를 추가할 수 있습니다.
방법1:
SELECT LAST_INSERT_ID() AS ID
insert into tb_content_category (id, parent_id, name,
status, sort_order, is_parent,
created, updated)
values (#{id,jdbcType=BIGINT}, #{parentId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR},
#{status,jdbcType=INTEGER}, #{sortOrder,jdbcType=INTEGER}, #{isParent,jdbcType=BIT},
#{created,jdbcType=TIMESTAMP}, #{updated,jdbcType=TIMESTAMP})
여기서 resultType은 반환 유형을 나타냅니다.ID는 방금 삽입한 ID를 반환합니다.
방법2:
mysql 데이터에 insert에서useGeneratedKeys="true"keyProperty="id"를 추가할 수 있습니다
insert into tb_content_category (id, parent_id, name,
status, sort_order, is_parent,
created, updated)
values (#{id,jdbcType=BIGINT}, #{parentId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR},
#{status,jdbcType=INTEGER}, #{sortOrder,jdbcType=INTEGER}, #{isParent,jdbcType=BIT},
#{created,jdbcType=TIMESTAMP}, #{updated,jdbcType=TIMESTAMP})
java 코드 가져오기 id
TbContentCategory record = new TbContentCategory();
record.setParentId(parentId);
record.setName(name);
Date date = new Date();
record.setCreated(date);
record.setUpdated(date);
record.setStatus(1);
record.setSortOrder(1);
record.setIsParent(false);
TbContentCategoryMapper.insert(record);
//insert ,id record ,
Long id = record.getId();
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
ssm에서 ansible 해 본 메모 (그냥 메모)SSM EC2에 SSM 에이전트를 넣고 EC2를 SSM의 관리하에 놓습니다. SSM 관리형 인스턴스에서 볼 수 있다면 OK 참고 링크 S3 버킷 생성 Ansible 템플릿을 zip으로 만들어 S3에 배치하기 위해. ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.