Commensal microbial–host interaction is crucial for host metabolism, growth, development, and immunity. However, research on microbial–host immunity in large animal models has been limited. This study was conducted to investigate the effects of the commensal microbiota on immune function in two model groups: germ-free (GF) and specific-pathogen-free (SPF) piglets. The weight and organ index of the spleen of the GF piglet were larger than those in the SPF piglet (P < 0.05). The histological structure of the red pulp area and mean area of germinal centers were larger in the SPF piglet than in the GF piglet (P < 0.05), whereas the areas of staining of B cells and T cells in the spleen and mesenteric lymph nodes (MLNs) were lower in the GF piglet (P < 0.05). We identified immune-related genes in the spleen and MLNs using RNA sequencing, and used real-time quantitative PCR to analyze the expression of core genes identified in gene set enrichment analysis. The expression levels of genes in the transforming growth factor-β/SMAD3 signaling pathway, Toll-like receptor 2/MyD88/nuclear factor-κB signaling pathway, and pro-inflammatory factor genes IL-6 and TNF-α in the spleen and MLNs were higher in the SPF piglet and in splenic lymphocytes compared with those in the GF and control group, respectively, under treatment with acetic acid, propionic acid, butyric acid, lipopolysaccharide (LPS), or concanavalin A (ConA). The abundances of plasma cells, CD8++ T cells, follicular helper T cells, and resting natural killer cells in the spleen and MLNs were significantly greater in the SPF piglet than in the GF piglet (P < 0.05). In conclusion, the commensal microbiota influenced the immune tissue structure, abundances of immune cells, and expression of immune-related pathways, indicating the importance of the commensal microbiota for spleen and MLNs development and function. In our study, GF piglet was used as the research model, eliminating the interference of microbiota in the experiment, and providing a suitable and efficient large animal research model for exploring the mechanism of “microbial-host” interactions.