zoukankan      html  css  js  c++  java
  • 最小化 Intellij 的springboot项目, jsp 页面

    新建项目

    spring initialezr,

    勾选 web,等,基本的,不勾选sql,

    在运行配置信息里,选择%MODULE_WORKING_DIR%

    添加dependency

    <dependency>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-jasper</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
    
            </dependency>
    <build>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>false</filtering>
                </resource>
                <resource>
                    <directory>src/main/webapp</directory>
                    <!--  注意打包后必须要放在此目录下才能被访问到 -->
                    <targetPath>META-INF/resources</targetPath>
                    <includes>
                        <include>**/**</include>
                    </includes>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
        <!--版本号,必须加,否则打包没有jsp页面-->
                    <version>1.4.2.RELEASE</version>
                    <configuration>
                        <excludes>
                            <exclude>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok</artifactId>
                            </exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </build>

    在main上,右键文件夹 webapp,然后建立jsp文件,index.jsp

    新建application.yml 文件

    spring:
      mvc:
        view:
          prefix: /
          suffix: .jsp

    新建controller文件夹,然后建立IndexController.java 文件

    package com.example.demo.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    @Controller
    public class IndexController {
      // @ResponseBody
        @RequestMapping("/")
        public String get(){
            return "index";
        }
    }

    即可访问http://localhost:8080/ 即可访问了。

    有时会碰到 没有maven的情况,这时,需要按 Ctrl+shift+ t ,然后再在view里,找到maven,就可以maven全周期了。

  • 相关阅读:
    TOMCAT添加管理用户认证
    NGINX配置详解及应用
    Zabbix部署
    NGINX+TOMCAT实现反向代理
    数据库-高级部分
    数据库-用户管理与pymysql
    数据库-表操作(CRUD)
    数据库-表关系练习
    数据库-表关系
    数据库-基础概念
  • 原文地址:https://www.cnblogs.com/sdgtxuyong/p/15176858.html
Copyright © 2011-2022 走看看