国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

SpringBoot里使用Servlet進(jìn)行請(qǐng)求的實(shí)現(xiàn)示例

瀏覽:5日期: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') 進(jìn)行使能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); }}

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

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 甘洛县| 汝阳县| 榆中县| 罗田县| 全州县| 嘉定区| 惠安县| 荣昌县| 格尔木市| 肇州县| 抚州市| 固安县| 满城县| 天峻县| 乌鲁木齐市| 南和县| 朔州市| 莒南县| 阜阳市| 和平县| 于田县| 儋州市| 门头沟区| 永顺县| 海林市| 古丈县| 昂仁县| 革吉县| 安阳县| 孟州市| 长垣县| 九龙县| 鄢陵县| 康平县| 上饶县| 秦安县| 龙陵县| 右玉县| 株洲市| 南和县| 凤台县|