There is no doubt that the vast majority of U.S. presidents had military backgrounds, with 31 of 43 presidents serving in the Armed Forces or National Guards in some capacity.
All but one were officers, James Buchanan served as a lowly private, and most held ranks above Major -- they were trained to lead soldiers into battle.
Almost as a reminder that military service wasn't a prerequisite for the presidency, John Adams, our second president, served only in the capacity of a diplomat and politician during the Revolution.