So my tentative recipe for using military as defence is:
grab migrants with military skills, set them to train always, make weapons and armour as soon as possible. As soon as the first soldiers go elite, recruit the next squads. Ambushes tend to appear during the second year, and can come as early as summer. Expect to lose a soldier or two against the first ambushes, but once they hit legendary, they only seem in serious danger when pitted against elite opponents, when facing serious bad luck or when trying to stem a siege.
I had turtled behind a raised bridge for several months in the second year, while training up my military and thinking about an adequate military architecture, after a station order in front of the depot led to one dead and one wounded archer (mostly my own fault, i had given them an archery target, so they had no ammo when the ambush came) and a swordsdwarf losing all use of one leg - she's a professional crutchwalker and legendary swordsmaster now.
So i designed a welcome room with a single-tile entrance, accessible only through diagonal corridors, to break line-of-sight for archers and deny opponents the advantage of numbers. In the third year, a four-squad ambush showed up and i got scared when i saw the graphics of two dead dwarfs. However, those were goblinised dwarfs who'd come along as part of the ambush. No losses among my military. Instead of a dwarf caravan, a vile force of darkness visited. It was just the cheap one spearsquad with a giant-olm riding captain. They had to pass through a hatch cover which i had set to tightly shut to keep tame animals contained, and the result was that the olm couldn't get through. I couldn't un-set it, either, because the hatch had been "taken by invaders". So that "siege" was repelled by the archer squad.
In the fourth year, a proper siege came up, jabberers, cave crawlers, cave crocodiles, about fifty gobbos. I just stationed everyone in the welcome room and let it play out. "Everyone" meant six legendaries, six "skilled" marksdwarfs, six talented-to-professional soldiers-in-training. Result: siege repelled. Losses of the attacker: 72. Losses of the defender: 2. One was a child who got face-stabbed by a kobold immediately before the siege came in (still a death "during" the siege), the other was a baby shield. One militarydwarf lost a leg, another had her guts torn but managed to walk it off. They're equipped with fine-to-superior bronze, which makes the chopping of armoured goblins a bit slow, but since they generally don't get surrounded, their defensive skills have kept them safe.
I must say i'm impressed. My first experiences with military were utterly awful, but with dedicated training and a decent defensive architecture, soldiers seem no less effective than traps.
I started the military buildup in the winter of the first year, we're near the end of year four and have six legendary-skill, and four more elite melee soldiers. Two soldiers seem to have gotten off on the wrong foot and are still stuck at adept/expert. Time to switch the four new elites to the action zone and make two new training pairs - all squads are pairs of different-weapon soldiers, which is the best non-cheaty setup i know of.