Vitamin B12 (VB12) has an important function in human physiology. However, analysis of VB12 at natural levels in foods or biological samples is difficult because of its very low concentration level and the presence of high-abundance components which can interfere with the measuring system. Thus, it is essential to develop efficient and selective enrichment approaches for VB12. Molecularly imprinted polymers (MIPs) have important applications from separation and sensing to catalysis. However, there is no report on the preparation of MIPs for VB12. Here, we use boronate affinity-based oriented surface imprinting to prepare MIPs for VB12. A VB12 template was first covalently immobilized onto the surface of boronic acid functionalized magnetic nanoparticles. Subsequently, a thin imprinting coating of poly(2-anilinoethanol) was formed to cover the substrate surface via in-water polymerization. After removing the template, 3D cavities complementary to the molecular size and shape of the template were formed in the imprinting layer. The imprinting coating was highly hydrophilic and presented limited residual boronic acid, thus non-specific binding was avoided. The prepared MIPs exhibited several highly favorable features, including excellent specificity, high binding strength and low binding pH. The prepared MIPs were successfully applied to the analysis of VB12 in human milk.