The toxic melamine was transformed to graphitic carbon nitrides nanosheets (GCNNs). The GCNNs was used to construct a fluorescence sensor for highly selective and sensitive detection of Hg2+. The sensor was successfully employed for the detection of Hg2+ in the lake water and milk samples.