springboot结合jsp模板开发

一、为什么没有用原生的模板

        开发分工问题。

二、Springboot对jsp的支持很差

        我是如何解决springboot和Jsp的结合问题的。

        关键点:部署发布问题:

工程结构

2.1 发布jar包

依赖springboot内嵌tomcat特质,以及项目独立性,依然推荐jar包发布。

处理要点:

2.11.jsp支持:

appliation.properties:

### web
server.port=8085
#server.servlet.context-path=/hecore

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix= .jsp

## 数据源配置
spring.datasource.url=jdbc:mysql://localhost:3306/labor_statistics?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=root
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver

# Mybatis 配置,指定了 mybatis 基础配置文件和实体类映射文件的地址
mybatis.mapperLocations=classpath:mapper/**/*.xml
mybatis.typeAliasesPackage=com.hecore.laborstatistics.model

2.12.重点 pom文件配置

jar 包还有后续配置

<?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.hecore.master</groupId>
    <artifactId>labor</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>labor-statistics-single</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>

    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot -->



    <parent>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath/>
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>

    <dependencies>

        <!--jsp页面使用jstl标签 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <!--用于编译jsp -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.1</version>
        </dependency>


        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls</artifactId>
            <version>2.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls-jexcel</artifactId>
            <version>1.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls-poi</artifactId>
            <version>1.0.12</version>
        </dependency>
        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls-reader</artifactId>
            <version>2.0.2</version>
        </dependency>


        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>6.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>RELEASE</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
         <!--打webapp资源包-->
        <resources>
            <resource>
                <directory>src/main/webapp</directory>
                <targetPath>META-INF/resources</targetPath>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
       
        </resources>
        <!--插件用于解决项目没有主菜单属性,并注意 用jar包方式使用jsp必须用1.4.2的版本-->
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.4.2.RELEASE</version>
            </plugin>
        </plugins>
    </build>
</project>

2.2 发布war包

2.21 pom去掉原生tomcat,设置war

     

          <packaging>war</packaging>

         <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-tomcat</artifactId>
           <scope>provided</scope>
        </dependency>

2.22 修改启动类

   package com.hecore.labors;

    import org.mybatis.spring.annotation.MapperScan;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;

    @SpringBootApplication
    @MapperScan(value = "com.hecore.laborstatistics.dao")
    public class LaborStatisticsApplication  extends SpringBootServletInitializer {
         @Override
          protected SpringApplicationBuilder configure(SpringApplicationBuilderapplication) {
                  return application.sources(LaborStatisticsApplication.class);

          }
    }
发布了49 篇原创文章 · 获赞 8 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_24935049/article/details/90411805
今日推荐