Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package br.com.gumga.academia.aplicacao; import br.com.gumga.academia.entidade.Cliente; import br.com.gumga.academia.entidade.ItemPedido; import br.com.gumga.academia.entidade.Pedido; import br.com.gumga.academia.entidade.Produto; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.stereotype.Component; /** * * @author Jefferson */ @Component public class MainService3 { @Autowired private ClienteService clienteService; @Autowired private ProdutoService produtoService; @Autowired private PedidoService pedidoService; public MainService3() { } public void run() { Cliente cliente = new Cliente("Gumga Cliente"); clienteService.salvar(cliente); clienteService.buscarTodos().forEach((cli) -> { System.out.println(cli.getNome()); }); Produto produto = new Produto("Caixa", 100.00); produtoService.salvar(produto); Pedido pedido = new Pedido(cliente); pedido.addItem(new ItemPedido(produto, 150.00)); pedidoService.salvar(pedido); pedidoService.buscarTodos().forEach((ped) -> { System.out.println(ped.getId() + " - " + ped.getCliente().getNome()); ped.getItens().forEach((item) -> { System.out.println(item.getProduto().getNome() + " " + item.getValorVenda()); }); }); } public static void main(String[] args) { ApplicationContext ctx = new AnnotationConfigApplicationContext(Aplicacao.class); MainService3 ms = ctx.getBean(MainService3.class); ms.run(); } }