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

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

SpringBoot里使用Servlet進行請求的實現示例

瀏覽:6日期: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進行請求的實現示例的文章就介紹到這了,更多相關SpringBoot Servlet請求內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 蚌埠市| 吴忠市| 且末县| 子长县| 同江市| 颍上县| 界首市| 外汇| 台北市| 西安市| 方城县| 霞浦县| 广平县| 湖南省| 额济纳旗| 大兴区| 宣恩县| 涞水县| 社旗县| 旺苍县| 乌兰浩特市| 昌平区| 林甸县| 涞水县| 舒兰市| 岳西县| 惠水县| 柞水县| 井陉县| 万全县| 综艺| 门源| 娱乐| 越西县| 镇远县| 罗山县| 平定县| 恩施市| 枣强县| 安陆市| 凤城市|