Example 4 Find the maximum of $y=\sin ^{2} x+2 \sin x \cos x+3 \cos ^{2} x$.
Solve: The original function can be transformed into $y=2+2 \sin 2 x+\cos 2 x$. Since $\sin ^{2} 2 x+\cos ^{2} 2 x=1$, by the corollary, we get $2 \geqslant(y-2)^{2}$, so $|y-2| \leqslant \sqrt{2}$, thus $y_{\max }=2+\sqrt{2}, y_{\min }=2-\sqrt{2}$.