栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

瑞奇外卖(1) - Maven项目环境搭建完毕,使用idea上传Gitee正常

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

瑞奇外卖(1) - Maven项目环境搭建完毕,使用idea上传Gitee正常

文章目录
  • Maven项目搭建
    • 新建maven工程
      • 目录与名称
      • 检查编码、maven仓库配置、jdk配置
      • 添加xml依赖、继承Springboot父类(2.5.4)
      • yml文件
    • 编写启动类
      • 测试通过
  • 导入前端页面
    • backend(后端后台功能页面)
    • front(前端面板页面)
  • 配置mvc框架的静态资源映射
    • 新建WebMvcConfig.java
    • 编写ReggieApplication.java入口
    • 启动测试成功
  • 上传git成功(使用idea上传)

Maven项目搭建 新建maven工程

目录与名称

检查编码、maven仓库配置、jdk配置

maven

jdk

添加xml依赖、继承Springboot父类(2.5.4)


    4.0.0
    
    
        org.springframework.boot
        spring-boot-starter-parent
        2.5.4
         
    

    com.taotao
    reggie_take_out
    1.0-SNAPSHOT




    
        1.8
    

    

        
            org.springframework.boot
            spring-boot-starter
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        

        
            org.springframework.boot
            spring-boot-starter-web
            compile
        

        
            com.baomidou
            mybatis-plus-boot-starter
            3.4.2
        

        
            org.projectlombok
            lombok
            1.18.20
        

        
            com.alibaba
            fastjson
            1.2.76
        

        
            commons-lang
            commons-lang
            2.6
        

        
            mysql
            mysql-connector-java
            runtime
        

        
            com.alibaba
            druid-spring-boot-starter
            1.1.23
        

    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
                2.4.5
            
        
    


yml文件
server:
  port: 8080
spring:
  application:
    name: reggie_take_out
  datasource:
    druid:
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://localhost:3306/reggie?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
      username: root
      password: 12345
mybatis-plus:
  configuration:
#    mybatis-plus自动映射
#    address_book--->AddressBook
#    user_name---->userName
    #在映射实体或者属性时,将数据库中表名和字段名中的下划线去掉,按照驼峰命名法映射
    map-underscore-to-camel-case: true
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  global-config:
    db-config:
      id-type: ASSIGN_ID
编写启动类

package com.taotao;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SuppressWarnings({"all"})
@Slf4j
@SpringBootApplication
public class reggie {
    public static void main(String[] args) {
        log.info("项目启动成功");
    }
}
测试通过

导入前端页面
  • 直接复制黏贴黑马的资料

backend(后端后台功能页面) front(前端面板页面)

此时我们虽然已经复制过来了页面,但是启动项目后依然不能正常访问,因为我们没有放在static目录下(静态资源映射)

配置mvc框架的静态资源映射
  • 目的就是加载访问前端页面
  • 当然你也可以把前端页面放入到static目录下,只是不建议如此而已
新建WebMvcConfig.java
package com.taotao.reggie.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;


@SuppressWarnings({"all"})
//此注解用于记录日志,方便调试
@Slf4j
//Configuration注解说明了这是一个配置类
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
    
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info("开始静态资源映射...");
        registry.addResourceHandler("/backend
@SuppressWarnings({"all"})
@Slf4j
@SpringBootApplication
public class ReggieApplication {
    public static void main(String[] args) {
        SpringApplication.run(ReggieApplication.class,args);
        log.info("项目启动成功");
    }
}

启动测试成功

上传git成功(使用idea上传)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/932852.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号