本文整理了Java中com.example.model.Base
类的一些代码示例,展示了Base
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base
类的具体详情如下:
包路径:com.example.model.Base
类名称:Base
暂无
代码示例来源:origin: making/spring-boot-db-samples
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Pizza)) return false;
Pizza pizza = (Pizza) o;
if (id != null ? !id.equals(pizza.id) : pizza.id != null) return false;
if (name != null ? !name.equals(pizza.name) : pizza.name != null) return false;
if (price != null ? !price.equals(pizza.price) : pizza.price != null) return false;
if (toppings != null ? !toppings.equals(pizza.toppings) : pizza.toppings != null) return false;
return base != null ? base.equals(pizza.base) : pizza.base == null;
}
代码示例来源:origin: making/spring-boot-db-samples
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (price != null ? price.hashCode() : 0);
result = 31 * result + (toppings != null ? toppings.hashCode() : 0);
result = 31 * result + (base != null ? base.hashCode() : 0);
return result;
}
}
代码示例来源:origin: making/spring-boot-db-samples
public Pizza toPizza(Long id) {
Pizza pizza = new Pizza();
pizza.setId(id);
pizza.setName(name);
pizza.setPrice(price);
Base base = new Base(id);
base.setName(baseName);
pizza.setBase(base);
pizza.setToppings(new ArrayList<>());
return pizza;
}
}
代码示例来源:origin: making/spring-boot-db-samples
@Bean
CommandLineRunner runner(PizzaRepository pizzaRepository) {
return a -> {
Pizza pizza = new Pizza();
pizza.setBase(new Base(1L));
pizza.setToppings(Arrays.asList(new Topping(1L), new Topping(2L), new Topping(3L), new Topping(4L), new Topping(5L)));
pizza.setName("Hello Pizza");
pizza.setPrice(new BigDecimal("1000"));
pizzaRepository.save(pizza);
};
}
}
代码示例来源: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
pizza.setName(tuple.get(qPizza.name));
pizza.setPrice(tuple.get(qPizza.price));
com.example.model.Base base = new Base(tuple.get(qBase.id));
base.setId(tuple.get(qBase.id));
base.setName(tuple.get(qBase.name));
pizza.setBase(base);
pizza.setToppings(e.getValue().stream().map(subTuple -> {
代码示例来源:origin: making/spring-boot-db-samples
public List<Pizza> findOrderByIdAsc() {
return pizzaDao.findOrderByIdAsc().stream()
.collect(Collectors.groupingBy(x -> x.id))
.entrySet()
.stream()
.map(e -> {
com.example.doma.Pizza dto = e.getValue().get(0);
Pizza pizza = new Pizza();
pizza.setId(dto.id);
pizza.setName(dto.name);
pizza.setPrice(dto.price);
Base base = new Base(dto.id);
base.setName(dto.baseName);
pizza.setBase(base);
pizza.setToppings(e.getValue().stream()
.map(x -> {
Topping topping = new Topping(x.toppingId);
topping.setName(x.toppingName);
return topping;
})
.collect(Collectors.toList()));
return pizza;
})
.collect(Collectors.toList());
}
代码示例来源:origin: making/spring-boot-db-samples
@Bean
CommandLineRunner runner(PizzaRepository pizzaRepository) {
return a -> {
Pizza pizza = new Pizza();
pizza.setBase(new Base(1L));
pizza.setToppings(Arrays.asList(new Topping(1L), new Topping(2L), new Topping(3L), new Topping(4L), new Topping(5L)));
pizza.setName("Hello Pizza");
pizza.setPrice(new BigDecimal("1000"));
pizzaRepository.save(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
public List<Pizza> findOrderByIdAsc() {
return jdbcTemplate.query("SELECT p.id, p.name, p.price, b.id AS baseId, b.name AS baseName, t.id AS toppingId, t.name AS toppingName FROM pizza p INNER JOIN base b ON (b.id = p.base_id) INNER JOIN pizza_toppings pt ON (pt.pizza_id = p.id) INNER JOIN topping t ON (t.id = pt.toppings_id) ORDER BY p.id ASC", rs -> {
List<Pizza> pizzas = new ArrayList<>();
Pizza pizza = null;
while (rs.next()) {
Long pizzaId = rs.getLong("id");
if (pizza == null || !pizzaId.equals(pizza.getId())) {
pizza = new Pizza();
pizza.setId(pizzaId);
pizza.setName(rs.getNString("name"));
pizza.setPrice(rs.getBigDecimal("price"));
Base base = new Base(rs.getLong("baseId"));
pizza.setBase(base);
base.setName(rs.getString("baseName"));
pizza.setToppings(new ArrayList<>());
pizzas.add(pizza);
}
Topping topping = new Topping(rs.getLong("toppingId"));
topping.setName(rs.getString("toppingName"));
pizza.getToppings().add(topping);
}
return pizzas;
});
}
代码示例来源:origin: making/spring-boot-db-samples
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (price != null ? price.hashCode() : 0);
result = 31 * result + (toppings != null ? toppings.hashCode() : 0);
result = 31 * result + (base != null ? base.hashCode() : 0);
return result;
}
}
代码示例来源:origin: making/spring-boot-db-samples
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Pizza)) return false;
Pizza pizza = (Pizza) o;
if (id != null ? !id.equals(pizza.id) : pizza.id != null) return false;
if (name != null ? !name.equals(pizza.name) : pizza.name != null) return false;
if (price != null ? !price.equals(pizza.price) : pizza.price != null) return false;
if (toppings != null ? !toppings.equals(pizza.toppings) : pizza.toppings != null) return false;
return base != null ? base.equals(pizza.base) : pizza.base == null;
}
代码示例来源:origin: making/spring-boot-db-samples
@Bean
CommandLineRunner runner(PizzaRepository pizzaRepository) {
return a -> {
Pizza pizza = new Pizza();
pizza.setBase(new Base(1L));
pizza.setToppings(Arrays.asList(new Topping(1L), new Topping(2L), new Topping(3L), new Topping(4L), new Topping(5L)));
pizza.setName("Hello Pizza");
pizza.setPrice(new BigDecimal("1000"));
pizzaRepository.save(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
public List<Pizza> findOrderByIdAsc() {
return pizzaDao.findOrderByIdAsc().stream()
.collect(Collectors.groupingBy(com.example.jdbi.Pizza::getId))
.entrySet()
.stream()
.map(e -> {
com.example.jdbi.Pizza dto = e.getValue().get(0);
Pizza pizza = new Pizza();
pizza.setId(dto.getId());
pizza.setName(dto.getName());
pizza.setPrice(dto.getPrice());
Base base = new Base(dto.getId());
base.setName(dto.getBaseName());
pizza.setBase(base);
pizza.setToppings(e.getValue().stream()
.map(x -> {
Topping topping = new Topping(x.getToppingId());
topping.setName(x.getToppingName());
return topping;
})
.collect(Collectors.toList()));
return pizza;
})
.collect(Collectors.toList());
}
代码示例来源:origin: making/spring-boot-db-samples
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (price != null ? price.hashCode() : 0);
result = 31 * result + (toppings != null ? toppings.hashCode() : 0);
result = 31 * result + (base != null ? base.hashCode() : 0);
return result;
}
}
代码示例来源:origin: making/spring-boot-db-samples
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Pizza)) return false;
Pizza pizza = (Pizza) o;
if (id != null ? !id.equals(pizza.id) : pizza.id != null) return false;
if (name != null ? !name.equals(pizza.name) : pizza.name != null) return false;
if (price != null ? !price.equals(pizza.price) : pizza.price != null) return false;
if (toppings != null ? !toppings.equals(pizza.toppings) : pizza.toppings != null) return false;
return base != null ? base.equals(pizza.base) : pizza.base == null;
}
代码示例来源:origin: making/spring-boot-db-samples
@Bean
CommandLineRunner runner(PizzaRepository pizzaRepository) {
return a -> {
Pizza pizza = new Pizza();
pizza.setBase(new Base(1L));
pizza.setToppings(Arrays.asList(new Topping(1L), new Topping(2L), new Topping(3L), new Topping(4L), new Topping(5L)));
pizza.setName("Hello Pizza");
pizza.setPrice(new BigDecimal("1000"));
pizzaRepository.save(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
public List<Pizza> findOrderByIdAsc() {
return pizzaMapper.findOrderByIdAsc().stream()
.collect(Collectors.groupingBy(com.example.mybatis.Pizza::getId))
.entrySet()
.stream()
.map(e -> {
com.example.mybatis.Pizza dto = e.getValue().get(0);
Pizza pizza = new Pizza();
pizza.setId(dto.getId());
pizza.setName(dto.getName());
pizza.setPrice(dto.getPrice());
Base base = new Base(dto.getId());
base.setName(dto.getBaseName());
pizza.setBase(base);
pizza.setToppings(e.getValue().stream()
.map(x -> {
Topping topping = new Topping(x.getToppingId());
topping.setName(x.getToppingName());
return topping;
})
.collect(Collectors.toList()));
return pizza;
})
.collect(Collectors.toList());
}
内容来源于网络,如有侵权,请联系作者删除!