Example 5 Find the maximum and minimum values of the function $y=\frac{x}{x^{2}+1}$. Analysis: Notice that its structure is basically consistent with the universal formula
$$
\sin \theta=\frac{2 \tan \frac{\theta}{2}}{1+\tan ^{2} \frac{\theta}{2}}
$$

Therefore, a trigonometric substitution can be used.
Solution: Note that $x \in \mathbf{R}$, we can set
$$
x=\tan \theta, \theta \in\left(-\frac{\pi}{2}, \frac{\pi}{2}\right) \text {. }
$$

Thus, $y=\frac{1}{2} \sin 2 \theta$.
Since $\theta \in\left(-\frac{\pi}{2}, \frac{\pi}{2}\right)$, then
$$
-\pi<2 \theta<\pi \text {. }
$$

Therefore, $-1 \leqslant \sin 2 \theta \leqslant 1$.
Hence $y_{\min }=-\frac{1}{2}, y_{\max }=\frac{1}{2}$.