You are currently viewing Spring Boot Masterclass – Call service method and print data in console 07

Spring Boot Masterclass – Call service method and print data in console 07

Hello, in this post we will call the expense service method to get the list of expenses and print it in the console. let’s begin. Inside the MasterController modify the handler method home()

MasterController.java




@Controller
public class MasterController {
	
	@Autowired
	ExpenseService expenseService;
	
	@RequestMapping("/")
	public ModelAndView home() {
		ModelAndView mav = new ModelAndView("home");
		mav.addObject("message", "List of expenses");
		List<Expense> expenses = expenseService.findAll();
		System.out.println(expenses);
		return mav;
	}
	
}

That’s it for this post. I will see you in the next post!

Thanks
Bushan SC

Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

This Post Has 2 Comments

  1. Dhiraj Deore

    this is printing .model.memory address instead of showing list data like ur console

  2. Dhiraj Deore

    edit – i have to manually set the to string constructor overriding the lobok’s ToString which was useless i dont know how

Leave a Reply