my batis plus Oacle 에 데이터 홈 키 를 삽입 하여 증가 합 니 다.

직접 코드 올 리 기:
@Data
@TableName(value="testplus")
//          
@KeySequence(value = "SEQ_TESTPLUS_ID", clazz = Integer.class)
public class TestPlus implements Serializable {
    /**
     *   
     * @TableId          ,        ,      yml   
     * AUTO:    ID  
     * INPUT:     ID
     * ID_WORKER:     ID,Long     
     * ID_WORKER_STR:        ID
     * UUID:     ID,UUID     
     * NONE:            
     */
     //    @TableId  
    @TableId(value = "ID", type = IdType.INPUT)
    private int id;
    private String name;
    private int age;
    private String gender;
    private double score;
}

실체 클래스 에 시퀀스 @ KeySequence (value = "SEQ TESTPLUS ID", clazz = Integer. class), @ TableId (value = "ID", type = IdType. INPUT) 설명 id 필드 를 추가 해 야 합 니 다.
mybatis-plus:
  mapper-locations: classpath:mapper/*.xml
  # Sequence         
  global-config:
    key-generator: com.baomidou.mybatisplus.incrementer.OracleKeyGenerator

application. yml 설정 파일 에 전역 설정 을 추가 하고 시퀀스 로 id 를 생 성 합 니 다.
@Mapper
public interface TestPlusMapper extends BaseMapper {
}

mapper 층
@Service
public class TestPlusServiceImpl extends ServiceImpl implements TestPlusService {
}

실현 계층
public interface TestPlusService extends IService {
}

서비스 계층
@RequestMapping(value="insert",method = RequestMethod.POST)
    public String insert(@RequestBody Map paramMap){
        TestPlus testPlus = new TestPlus();
        testPlus.setAge((Integer) paramMap.get("age"));
        testPlus.setGender((String)paramMap.get("gender"));
        testPlus.setName((String)paramMap.get("name"));
        testPlus.setScore((Integer) paramMap.get("score"));
        boolean flag = testPlusService.insert(testPlus);
        if(flag){
            return "    ";
        }
        return "    ";
    }

controller 층, 저 는 postman 테스트 를 사 용 했 습 니 다. testplus Service. insert (testplus) 방법 은 boolean 형식 을 되 돌려 주 었 습 니 다. ture 대표 에 게 성공 을 추 가 했 습 니 다. 실체 류 를 직접 전송 하면 데 이 터 를 추가 할 수 있 습 니 다. service, 실현 류, mapper 층 은 어떠한 방법 도 쓰 지 않 아 도 됩 니 다.처음에 학습 용 으로 쓰 였 는데, 어디 큰 신의 지적 에 맞지 않 겠 는가!

좋은 웹페이지 즐겨찾기