久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

SpringBoot里使用Servlet進行請求的實現(xiàn)示例

瀏覽:2日期:2023-03-30 14:36:35

首先,在main方法的類上添加注解:

@ServletComponentScan(basePackages = 'application.servlet')

示例代碼:

package application; import io.seata.spring.annotation.datasource.EnableAutoDataSourceProxy;import javafx.application.Application;import javafx.fxml.FXMLLoader;import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.web.servlet.ServletComponentScan;import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;import org.springframework.cache.annotation.EnableCaching;import org.springframework.cloud.openfeign.EnableFeignClients; import javax.annotation.Resource; /** * @author wtl */@SpringBootApplication@EnableFeignClients@EnableCaching@EnableAutoDataSourceProxy@MapperScan(basePackages = 'application.mybatis.mappers')@ServletComponentScan(basePackages = 'application.servlet')public class SpringBootMain extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(SpringBootMain.class,args); Application.launch(FxmlRunner.class,args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(SpringBootMain.class); }}

使用 @WebServlet(name = 'DownloadServlet',urlPatterns = '/test') 進行使能Servlet:

@WebServlet(name = 'DownloadServlet',urlPatterns = '/test')

示例:

package application.servlet; import application.service.BiliBiliIndexService;import lombok.SneakyThrows; import javax.annotation.Resource;import javax.servlet.*;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.IOException; /** * @author: wtl * @Date: 2020/7/5 * @Time: 18:48 * @Description: */@WebServlet(name = 'DownloadServlet',urlPatterns = '/test')public class DownloadServlet extends HttpServlet { @Resource private BiliBiliIndexService biliBiliIndexService; @SneakyThrows @Override protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { String aid = httpServletRequest.getParameter('aid'); String cid = httpServletRequest.getParameter('cid'); biliBiliIndexService.getVideoStream(aid,cid,httpServletRequest,httpServletResponse); }}

到此這篇關于SpringBoot里使用Servlet進行請求的實現(xiàn)示例的文章就介紹到這了,更多相關SpringBoot Servlet請求內容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持好吧啦網(wǎng)!

標簽: Spring
相關文章:
主站蜘蛛池模板: 南部县| 湘西| 北安市| 睢宁县| 淮南市| 澳门| 福州市| 鄂托克前旗| 子长县| 田东县| 武强县| 许昌市| 滨海县| 嘉祥县| 吐鲁番市| 东台市| 阳江市| 昭苏县| 三门县| 宜城市| 汕头市| 阳西县| 绵阳市| 三穗县| 威信县| 饶阳县| 张家川| 板桥市| 康乐县| 壶关县| 汽车| 称多县| 台江县| 永川市| 长葛市| 东丽区| 清新县| 拜泉县| 上思县| 吉林省| 汕尾市|