com.example.model.Base.getId()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.4k)|赞(0)|评价(0)|浏览(83)

本文整理了Java中com.example.model.Base.getId()方法的一些代码示例,展示了Base.getId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base.getId()方法的具体详情如下:
包路径:com.example.model.Base
类名称:Base
方法名:getId

Base.getId介绍

暂无

代码示例

代码示例来源:origin: making/spring-boot-db-samples

@Transactional
  public Pizza save(Pizza pizza) {
    GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcTemplate.update(con -> {
      PreparedStatement ps = con.prepareStatement("INSERT INTO pizza (base_id, name, price) VALUES (?, ?, ?)");
      ps.setLong(1, pizza.getBase().getId());
      ps.setString(2, pizza.getName());
      ps.setBigDecimal(3, pizza.getPrice());
      return ps;
    }, keyHolder);
    long pizzaId = keyHolder.getKey().longValue();
    jdbcTemplate.batchUpdate("INSERT INTO pizza_toppings (pizza_id, toppings_id) VALUES (?, ?)",
        pizza.getToppings().stream().map(t -> new Object[]{pizzaId, t.getId()}).collect(Collectors.toList()));
    pizza.setId(pizzaId);
    return pizza;
  }
}

代码示例来源:origin: making/spring-boot-db-samples

@Transactional
  public Pizza save(Pizza pizza) {
    long pizzaId = pizzaDao.insertPizza(pizza.getBase().getId(), pizza.getName(), pizza.getPrice());
    pizzaDao.insertPizzaToppings(pizzaId, pizza.getToppings().stream().map(Topping::getId).collect(Collectors.toList()));
    pizza.setId(pizzaId);
    return pizza;
  }
}

代码示例来源:origin: making/spring-boot-db-samples

@Transactional
  public Pizza save(Pizza pizza) {
    pizza.setBaseId(pizza.getBase().getId());
    jdbcManager.insert(pizza).execute();
    jdbcManager.insertBatch(pizza.getToppings().stream().map(t -> new PizzaToppings(pizza.getId(), t.getId())).collect(Collectors.toList())).execute();
    return pizza;
  }
}

代码示例来源:origin: making/spring-boot-db-samples

@Transactional
  public Pizza save(Pizza pizza) {
    com.example.doma.Pizza dto = new com.example.doma.Pizza();
    dto.id = pizza.getId();
    dto.name = pizza.getName();
    dto.price = pizza.getPrice();
    dto.baseId = pizza.getBase().getId();
    pizzaDao.insert(dto);
    pizzaDao.insertToppings(pizza.getToppings().stream()
        .map(x -> {
          PizzaToppings pt = new PizzaToppings();
          pt.pizzaId = dto.id;
          pt.toppingsId = x.getId();
          return pt;
        }).collect(Collectors.toList()));
    return pizza;
  }
}

代码示例来源:origin: making/spring-boot-db-samples

@Transactional
public Pizza save(Pizza pizza) {
  try(Db db = Db.open(dataSource)) {
    com.example.iciql.Pizza p = new com.example.iciql.Pizza();
    p.baseId = pizza.getBase().getId();
    p.name = pizza.getName();
    p.price = pizza.getPrice();
    long pizzaId = db.insertAndGetKey(p);
    List<PizzaToppings> pizzaToppings = pizza.getToppings().stream().map(t -> {
      PizzaToppings pt = new PizzaToppings();
      pt.pizzaId = pizzaId;
      pt.toppingsId = t.getId();
      return pt;
    }).collect(Collectors.toList());
    db.insertAll(pizzaToppings);
    pizza.setId(pizzaId);
    return pizza;
  }
}

代码示例来源:origin: making/spring-boot-db-samples

@Transactional
  public com.example.model.Pizza save(com.example.model.Pizza modelPizza) {
    Pizza pizza = new Pizza();
    pizza.setName(modelPizza.getName());
    pizza.setPrice(modelPizza.getPrice());
    pizza.setBaseId(modelPizza.getBase().getId());
    pizzaBhv.insert(pizza);
    Long pizzaId = pizza.getId(); // generated by insert
    List<PizzaToppings> toppingsList = modelPizza.getToppings().stream().map(modelTopping -> {
      PizzaToppings toppings = new PizzaToppings();
      toppings.setPizzaId(pizzaId);
      toppings.setToppingsId(modelTopping.getId());
      return toppings;
    }).collect(Collectors.toList());
    pizzaToppingsBhv.batchInsert(toppingsList);
    return modelPizza;
  }
}

代码示例来源:origin: making/spring-boot-db-samples

@Transactional
  public Pizza save(Pizza pizza) {
    Long pizzaId = dslContext.insertInto(PIZZA, PIZZA.BASE_ID, PIZZA.NAME, PIZZA.PRICE)
        .values(pizza.getBase().getId(), pizza.getName(), pizza.getPrice())
        .returning(PIZZA.ID)
        .fetchOne()
        .getId();
    int[] x = dslContext.batch(pizza.getToppings().stream()
        .map(t -> dslContext
            .insertInto(PIZZA_TOPPINGS, PIZZA_TOPPINGS.PIZZA_ID, PIZZA_TOPPINGS.TOPPINGS_ID)
            .values(pizzaId, t.getId()))
        .toArray(Query[]::new))
        .execute();
    pizza.setId(pizzaId);
    return pizza;
  }
}

代码示例来源:origin: making/spring-boot-db-samples

@Transactional
  public Pizza save(Pizza pizza) {
    com.example.mybatis.Pizza dto = new com.example.mybatis.Pizza();
    dto.setName(pizza.getName());
    dto.setPrice(pizza.getPrice());
    dto.setBaseId(pizza.getBase().getId());
    pizzaMapper.insert(dto);
    pizzaMapper.flush(); // generate key here in BATCH mode
    pizza.getToppings().forEach(t -> pizzaMapper.insertToppings(new PizzaToppings(dto.getId(), t.getId())));
    return pizza;
  }
}

代码示例来源:origin: making/spring-boot-db-samples

@Transactional
  public Pizza save(Pizza pizza) {

    Long pizzaId = sqlQueryFactory.insert(qPizza)
        .columns(qPizza.baseId, qPizza.name, qPizza.price)
        .values(pizza.getBase().getId(), pizza.getName(), pizza.getPrice())
        .executeWithKey(Long.class);

    SQLInsertClause insert = sqlQueryFactory.insert(qPizzaToppings);
    pizza.getToppings().forEach(tpg -> insert.values(pizzaId, tpg.getId()).addBatch());
    insert.execute();

    pizza.setId(pizzaId);
    return pizza;
  }
}

代码示例来源:origin: making/spring-boot-db-samples

public Pizza save(Pizza pizza) {
  try (Connection con = sql2o.beginTransaction()) {
    long pizzaId = (long) con.createQuery("INSERT INTO pizza (base_id, name, price) VALUES (:baseId, :name, :price)", true)
        .addParameter("baseId", pizza.getBase().getId())
        .addParameter("name", pizza.getName())
        .addParameter("price", pizza.getPrice())
        .executeUpdate()
        .getKey();
    Query queryForPt = con.createQuery("INSERT INTO pizza_toppings (pizza_id, toppings_id) VALUES (:pizzaId, :toppingsId)");
    pizza.getToppings().forEach(t ->
        queryForPt
            .addParameter("pizzaId", pizzaId)
            .addParameter("toppingsId", t.getId())
            .addToBatch());
    queryForPt.executeBatch();
    con.commit();
  }
  return pizza;
}

相关文章