In this study, we prepared a 3D aerogel, PAN-C3N4, using polyacrylonitrile (PAN) and C3N4 as raw materials through a hydrothermal method. Subsequently, a layer of COFs (FT) was grown on its surface. We modeled its structure and compared it with experimental PXRD patterns to obtain the possible final crystal structure. Afterward, through functionalization with butyne, we prepared a 3D aerogel composite, PAN-C3N4@FT@Butyne, which can be applied to the adsorption of both mercury(II) and elemental mercury vapor. In a short span of time (25 min), the maximum adsorption capacities of mercury(II) and elemental mercury vapor were found to be as high as 830.1 mg/g and 463 mg/g, respectively. Importantly, in the fixed-bed column study, the influence of flow rate and initial concentration of mercury(II) was evaluated through breakthrough curves, yielding an adsorption capacity of 25.48 mg/g. Meanwhile, the application of the fixed bed column for industrial wastewater treatment displayed exceptional adsorptive capabilities, reduced the concentration of mercury (II) from 10.0 mg/L to less than 1.76 μg/L, significantly below the permissible limit for drinking water (2 μg/L). In addition, PAN-C3N4@FT@Butyne can be utilized as a chemodosimeter to detect mercury(II) in solution within a mere 5 s, with a detection limit of 0.1 ppb. Furthermore, COFs (BT) were cultivated within the PAN-C3N4 matrix as a control group, thereby demonstrating the widespread applicability of this strategy.