Biomedical magnesium is an ideal material for hard tissue repair and replacement. However, its rapid degradation and infection after implantation significantly hindersclinical applications. To overcome these two critical drawbacks, we describe an integrated strategybased on the changes in pH and Mg2+ triggered by magnesiumdegradation. This system can simultaneously offer anticorrosion and antibacterial activity. First, nanoengineered peptide-grafted hyperbranched polymers (NPGHPs) with excellent antibacterial activity were introduced to sodium alginate (SA) to construct a sensitive NPGHPs/SA hydrogel. The swelling degree, responsiveness, and antibacterial activity were then investigated,indicating that the system can perform dual stimulation of pH and Mg2+ with controllable antimicrobial properties. Furthermore, an intelligent platform was constructed by coating hydrogels on magnesium with polydopamine as the transition layer. The alkaline environment generated by the corrosion of magnesium reduces the swelling degree of the coatingso that the liquid is unfavorable for contacting the substrate, thus exhibiting superior corrosion resistance. Antibacterial testing shows that the material can effectively fight against bacteria, while hemolytic and cytotoxicity testing suggest that it is highly biocompatible. Thus, this work realizes the smart integration of anticorrosion and antibacterial properties of biomedical magnesium, thereby providing broader prospects for the use of magnesium.