springboot同时支持jsp+vue页面启动

1、参考文档链接

        参考上面文档边百度边改,现在可以了,分享下

2、Java项目目录结构

3、pom.xml内容

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelVersion>4.0.0</modelVersion>  <groupId>com.wxs</groupId>  <artifactId>test</artifactId>  <version>1.0-SNAPSHOT</version>  <packaging>war</packaging>  <name>test</name>  <!-- FIXME change it to the project's website -->  <url>http://www.example.com</url>  <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  <maven.compiler.source>17</maven.compiler.source>  <maven.compiler.target>17</maven.compiler.target> </properties>  <parent> <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-starter-parent</artifactId>  <version>1.5.9.RELEASE</version> </parent>  <dependencies> <dependency> <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-starter-web</artifactId> </dependency>  <!--要支持jsp需 添加servlet依赖模块 --><dependency> <groupId>javax.servlet</groupId>  <artifactId>javax.servlet-api</artifactId>  </dependency><!-- 要支持jsp需 添加jstl标签库依赖模块 --><dependency> <groupId>javax.servlet</groupId>  <artifactId>jstl</artifactId> </dependency>  <!-- 要支持jsp需 使用jsp引擎,springboot内置tomcat没有此依赖 --><dependency> <groupId>org.apache.tomcat.embed</groupId>  <artifactId>tomcat-embed-jasper</artifactId>  </dependency><dependency> <groupId>junit</groupId>  <artifactId>junit</artifactId>  <version>4.11</version>  <scope>test</scope> </dependency><!-- 要支持html 需添加thymeleaf --><dependency><groupId>org.thymeleaf</groupId><artifactId>thymeleaf-spring5</artifactId><version>3.0.15.RELEASE</version></dependency><dependency><groupId>org.thymeleaf</groupId><artifactId>thymeleaf</artifactId><version>3.0.15.RELEASE</version></dependency></dependencies>  <build><resources><!--要支持jsp需  springboot使用的web资源要编译到META-INF/resources--><resource><directory>src/main/webapp</directory><targetPath>META-INF/resources</targetPath><includes><include>**/*.*</include></includes></resource><resource><directory>src/main/resources</directory><includes><include>**/**</include></includes><filtering>false</filtering></resource></resources><pluginManagement> <!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->  <plugins><plugin> <artifactId>maven-clean-plugin</artifactId>  <version>3.1.0</version> </plugin>  <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->  <plugin> <artifactId>maven-resources-plugin</artifactId>  <version>3.0.2</version> </plugin>  <plugin> <artifactId>maven-compiler-plugin</artifactId>  <version>3.8.0</version> </plugin>  <plugin> <artifactId>maven-surefire-plugin</artifactId>  <version>2.22.1</version> </plugin>  <plugin> <artifactId>maven-jar-plugin</artifactId>  <version>3.0.2</version> </plugin>  <plugin> <artifactId>maven-install-plugin</artifactId>  <version>2.5.2</version> </plugin>  <plugin> <artifactId>maven-deploy-plugin</artifactId>  <version>2.8.2</version> </plugin>  <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->  <plugin> <artifactId>maven-site-plugin</artifactId>  <version>3.7.1</version> </plugin>  <plugin> <artifactId>maven-project-info-reports-plugin</artifactId>  <version>3.0.0</version> </plugin> </plugins> </pluginManagement> </build> 
</project>

4、WebConfig内容

package com.wxs.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.validation.MessageCodesResolver;
import org.springframework.validation.Validator;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.thymeleaf.spring5.SpringTemplateEngine;
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;
import org.thymeleaf.templateresolver.ITemplateResolver;import java.util.List;@Configuration@EnableWebMvcpublic class WebConfig implements WebMvcConfigurer {@Beanpublic ViewResolver viewResolver() {InternalResourceViewResolver resolver = new InternalResourceViewResolver();resolver.setPrefix("/jsp/");resolver.setSuffix(".jsp");resolver.setViewNames("*");resolver.setOrder(2);return resolver;}@Beanpublic ITemplateResolver templateResolver() {SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();templateResolver.setTemplateMode("HTML5");templateResolver.setPrefix("/");templateResolver.setSuffix(".html");templateResolver.setCharacterEncoding("utf-8");templateResolver.setCacheable(false);return templateResolver;}@Beanpublic SpringTemplateEngine templateEngine() {SpringTemplateEngine templateEngine = new SpringTemplateEngine();templateEngine.setTemplateResolver(templateResolver());// templateEnginereturn templateEngine;}@Beanpublic ThymeleafViewResolver viewResolverThymeLeaf() {ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();viewResolver.setTemplateEngine(templateEngine());viewResolver.setCharacterEncoding("utf-8");viewResolver.setOrder(1);viewResolver.setViewNames(new String[]{"dist/*", "vue/*"});return viewResolver;}@Overridepublic void configurePathMatch(PathMatchConfigurer pathMatchConfigurer) {}@Overridepublic void configureContentNegotiation(ContentNegotiationConfigurer contentNegotiationConfigurer) {}@Overridepublic void configureAsyncSupport(AsyncSupportConfigurer asyncSupportConfigurer) {}@Overridepublic void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {configurer.enable();}@Overridepublic void addFormatters(FormatterRegistry formatterRegistry) {}@Overridepublic void addInterceptors(InterceptorRegistry interceptorRegistry) {}@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler("/img/**").addResourceLocations("/img/");registry.addResourceHandler("/static/**").addResourceLocations("/WEB-INF/" + "/static/");registry.addResourceHandler("/js/**").addResourceLocations("/dist/js/");registry.addResourceHandler("/css/**").addResourceLocations("/dist/css/");registry.addResourceHandler("/wxs/**").addResourceLocations("file:C:/Users/amd/Desktop/");}@Overridepublic void addCorsMappings(CorsRegistry corsRegistry) {}@Overridepublic void addViewControllers(ViewControllerRegistry viewControllerRegistry) {}@Overridepublic void configureViewResolvers(ViewResolverRegistry viewResolverRegistry) {}@Overridepublic void addArgumentResolvers(List<HandlerMethodArgumentResolver> list) {}@Overridepublic void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> list) {}@Overridepublic void configureMessageConverters(List<HttpMessageConverter<?>> list) {}@Overridepublic void extendMessageConverters(List<HttpMessageConverter<?>> list) {}@Overridepublic void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> list) {}@Overridepublic void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> list) {}@Overridepublic Validator getValidator() {return null;}@Overridepublic MessageCodesResolver getMessageCodesResolver() {return null;}
}

5、TestController内容

package com.wxs.controller;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
public class TestController {@RequestMapping("/jsp")public String jsp(Model model) {return "index2";}@GetMapping("/vue")public String vue(Model model) {return "dist/index";}
}

6、测试

http://localhost:6066/jsp   jsp请求

http://localhost:6066/vue  vue请求

7、完事了~~~

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/623476.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

dbever可视化工具使用

分别遵循 1 2 3步骤 可以查看除了执行后的控制台以外的其他窗口。

波分设备的功能和应用

波分设备主要利用光波在光纤中传输数据&#xff0c;具有以下功能&#xff1a; 高速数:据传输。波分技术能提供比传统电信技术更高的数据传输速度。 大带宽:通过将不同频率的光波分配到不同的频段中&#xff0c;波分技术使得更多数据可以同时传输。低衰减&#xff1a;光波在光…

Java——封装、访问修饰符、包

目录 一.封装的概念 二.访问限定符 三.封装扩展之包 1.包的概念 2.导入包中的类 3.自定义包 4.包的访问权限控制举例 5.常见的包 一.封装的概念 面向对象程序三大特性&#xff1a;封装、继承、多态。而类和对象阶段&#xff0c;主要研究的就是封装特性。何为封装呢&am…

electron项目打包慢、打包报错

项目使用了electron框架&#xff0c;在第一次打包或者网络条件不好的环境下进行打包时熟速度慢的出奇&#xff0c;甚至经常出现打包失败的情况&#xff08;如上面图片的报错&#xff09;。 这是因为&#xff0c;在electron打包的过程中&#xff0c;需要去官方源https://github.…

如何在 VM 虚拟机中安装 OpenEuler 操作系统保姆级教程(附链接)

一、VMware Workstation 虚拟机 若没有安装虚拟机的可以参考下篇文章进行安装&#xff1a; 博客链接https://eclecticism.blog.csdn.net/article/details/135713915 二、OpenEuler 镜像 点击链接前往官网 官网 选择第一个即可 三、安装 OpenEuler 打开虚拟机安装 Ctrl …

客户资料不翼而飞?企业数据保护攻略

在数字化经济时代&#xff0c;企业的客户资料等同于商业生命线&#xff0c;一旦泄露&#xff0c;后果不堪设想。例如&#xff0c;2017年Equifax的数据泄露事件&#xff0c;造成超过1.4亿用户的个人信息外泄&#xff0c;不仅给用户带来风险&#xff0c;也让公司名誉受损&#xf…

IP定位技术原理详细阐述

IP定位技术原理主要基于IP地址与地理位置之间的关联&#xff0c;通过一系列的技术手段&#xff0c;实现对网络设备的物理位置进行精确或大致的定位。以下是对IP定位技术原理的详细阐述。 首先&#xff0c;我们需要了解IP地址的基本概念。IP地址是互联网协议地址的简称&#xff…

【Linux】Socket编程接口 | 实现简单的UDP网络程序

文章目录 一、预备知识理解源IP地址和目的IP地址理解源mac地址和目的mac地址认识端口号理解源端口号和目的端口号理解“端口号&#xff08;PORT&#xff09;”和“进程ID&#xff08;PID&#xff09;” 认识TCP和UDP协议TCP协议UDP协议 网络字节序为什么网络字节序采用的是大端…

linux项目部署 解决Nginx浏览器刷新出现404,但是不刷新是能够正常请求成功

文章目录 目录 文章目录 安装流程 小结 概要安装流程技术细节小结 概要 提示&#xff1a;部署成功&#xff0c;访问登录页面登录也成功&#xff0c;强制刷新浏览器报404问题 进入到系统 刷新页面 解决流程 参考如图&#xff0c;再下面添加这条配置信息 location / {try_file…

中职人工智能技术与应用课程及就业方向

泰迪智能科技推出中职人工智能专业一站式建设解决方案&#xff0c;从解决人工智能专业的专业建设难点出发&#xff0c;让教学实训更简单为理念&#xff0c;助力学校完成人工智能相关专业的专业建设。 人工智能技术应用专业课程&#xff1a; 人工智能应用导论、程序设计基础…

ClickHouse--17--聚合函数总结

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 环境1.创建clickhouse表2.插入数据 函数(1)count&#xff1a;计算行数(2)min&#xff1a;计算最小值(3)max&#xff1a;计算最大值(4)sum&#xff1a;计算总和&…

Ollama、FastGPT大模型RAG知识库结合使用案例

参考: https://ollama.com/download/linux https://doc.fastai.site/docs/intro/ https://blog.csdn.net/m0_71142057/article/details/136738997 https://doc.fastgpt.run/docs/development/custom-models/m3e/ https://concise-eater-d47.notion.site/Ollama-Fastgpt-b170…