Mybatis在插入自增字段時,會對當前對象未賦值的自增字段進行賦值,以下即自動完成對id的賦值java
OrderItem orderItem = new OrderItem(); System.out.println("=========="); System.out.println(orderItem);//此時輸出OrderItem{id=null, pid=null, oid=null, uid=null, number=null, product=null} orderItem.setPid(pid); orderItem.setUid(user.getId()); orderItem.setNumber(num); System.out.println("=========="); System.out.println(orderItem);//此時輸出OrderItem{id=null, pid=91, oid=null, uid=1, number=1, product=null} orderItemService.add(orderItem); System.out.println("=========="); System.out.println(orderItem);//此時輸出OrderItem{id=6, pid=91, oid=null, uid=1, number=1, product=null}