The invention discloses an encoding gene of porcine parvovirus VP2 protein, a method of prokaryotically expressing VP2 protein virus-like particles, and application of the method in vaccine preparation. Sequences are optimized, VP2 gene is artificially synthesized, the synthesized gene is inserted into pET28a vector, the gene and chaperone protein plasmids are co-transferred to BL21(DE3) host bacteria, the VP2 protein and chaperone protein are co-expressed to promote correct folding of the VP2 protein. Experiments prove that recombinant bacteria expressed VP2 protein can be self-assembled in vitro and has good immunogenicity; by immunizing mice and guinea pigs with the virus-like particle subunit vaccine prepared with the VP2 protein expressed herein, it is possible to induce the production of a high level of hemagglutination inhibition antibodies and neutralizing antibodies, and the vaccine can prevent guinea pigs from being affected by strong porcine parvovirus. The recombinant bacteria according to the invention can be utilized to efficiently prepare porcine parvovirus virus-like particles, the production cost is low, operation is simple, and biosafety is better.