After numerous sky survey devices such as Large Sky Area Multi-Object Fiber Spectroscopic Telescope (LAMOST) were put into use, astronomical research officially entered a new era of explosive data growth. Massive amounts of data make the theoretical research on stellar evolution simple, but they bring huge challenges to the task of spectral classification. In order to classify celestial spectra faster and better, we need to borrow the tool of deep learning. In the field of traditional stellar spectral classification, Convolutional Neural Network (CNN) is mostly used as the feature extraction module to extract stellar spectral features. CNN extracts the local features of spectral data through convolution operations, eliminates redundant information, and compresses the data in a maximized pooling manner. However, the fully connected layer of CNN does not have an effective long-range dependent feature extraction function. The sliding window local attention mechanism of the Swin Transformer enables information interaction between the collected adjacent Windows, demonstrating the correlation of spectral lines at different wavelengths. The global modeling ability of the sliding window also enables the extracted features to start from the full spectrum, ensuring the integrity of the spectral information. Meanwhile, the Swin Transformer retains the characteristics of multi-scale feature extraction of CNN. Different receptive fields can obtain both the features of narrow spectral lines and those of wide spectral lines. Therefore, based on the Swin Transformer model, we have built the Swin Transformer-ResNet-DenseNet (StRD) automatic classification algorithm for stellar spectra. The algorithm consists of four parts: (1) Data pre-processing; (2) Feature extraction from the data;(3) Model modification;(4) Automatic classification. Feature extraction forms the core of the StRD algorithm. The extracted data reflects the correlation of spectral lines at different wavelengths of the stellar spectrum and captures multi-scale features. When the StRD algorithm is used to automatically classify the spectra of A, B, dM, F, G, gM and K type stars with an R-band signal-to-noise ratio greater than 30, the classification accuracy is 0.98. This is higher than the classification accuracies of the CNN+Bayes, CNN+KNN, CNN+SVM, CNN+Adaboost and CNN+RF algorithms: 0.862, 0.876, 0.894, 0.868 and 0.889 respectively.