• RouYi-Cloud平台 ---项目的启动、登录功能是怎么实现的、怎么样创建新模块


    RouYi-Cloud平台

    1、项目启动

    (1)环境准备

    JDK >= 1.8 (推荐1.8版本)
    Mysql >= 5.7.0 (推荐5.7版本)
    Redis >= 3.0
    Maven >= 3.0
    Node >= 12
    nacos >= 1.1.0 (ruoyi-cloud >= 3.0.0需要下载nacos >= 2.x.x版本)
    sentinel >= 1.6.0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    (2)后台运行

    • 启动本地的Nacos2.1:startup.cmd -m standalone

    在这里插入图片描述

    在这里插入图片描述

    • 启动本地的Redis服务

    在这里插入图片描述

    在这里插入图片描述

    1、前往Gitee下载页面(https://gitee.com/y_project/RuoYi-Cloud (opens new window))下载解压到工作目录
    2、导入到项目到idea中。
    3、创建数据库ry-cloud并导入数据脚本ry_2021xxxx.sql(必须),quartz.sql(可选)
    4、创建数据库ry-config并导入数据脚本ry_config_2021xxxx.sql(必须)
    5、配置nacos持久化,修改conf/application.properties文件,增加支持mysql数据源配置

    # db mysql
    spring.datasource.platform=mysql
    db.num=1
    db.url.0=jdbc:mysql://localhost:3306/ry-config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
    db.user=root
    db.password=123456
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    提示

    配置文件application.properties是在下载的nacos-serverconf目录下。
    最新RuoYi-Cloud版本>=3.0.0需要下载的nacos-server必须>=2.x.x版本。
    默认配置单机模式,nacos集群/多集群部署模式参考 (Nacos支持三种部署模式 (opens new window))

    6、打开运行基础模块(启动没有先后顺序)

    • RuoYiGatewayApplication (网关模块 必须)
    • RuoYiAuthApplication (认证模块 必须)
    • RuoYiSystemApplication (系统模块 必须)
    • RuoYiMonitorApplication (监控中心 可选)
    • RuoYiGenApplication (代码生成 可选)
    • RuoYiJobApplication (定时任务 可选)
    • RuoYFileApplication (文件服务 可选)

    在这里插入图片描述

    在这里插入图片描述

    7、集成seata分布式事务(可选配置,默认不启用)

    创建数据库ry-seata并导入数据脚本ry_seata_2021xxxx.sql

    (3)前端运行

    # 进入项目目录
    cd ruoyi-ui
    
    # 安装依赖
    npm install
    
    # 强烈建议不要用直接使用 cnpm 安装,会有各种诡异的 bug,可以通过重新指定 registry 来解决 npm 安装速度慢的问题。
    npm install --registry=https://registry.npmmirror.com
    
    # 本地开发 启动项目
    npm run dev
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    在这里插入图片描述

    打开浏览器,输入:(http://localhost:80 (opens new window)) 默认账户/密码 admin/admin123
    若能正确展示登录页面,并能成功登录,菜单及页面展示正常,则表明环境搭建成功

    在这里插入图片描述

    2、登录实现

    (1)生成验证码

    1、前端代码实现

    • 基本思路

    后端生成一个表达式:6+2=8

    1+1=?@2

    1+1=?转成图片,传到前端展示

    8 存入到Redis中

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    • 代码实现

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    访问地址:http://localhost:81/dev-api/code

    Vue获取图片请求的是前端,再反向代理映射到后端,解决跨域问题

    /dev-api 被替换成 ’ ’ ,再映射到:http://localhost:8080,变成:http://localhost:8080/code

    在这里插入图片描述

    2、后端代码实现

    3、创建新模块

    (1)创建自己的模块

    搭建好之后的项目结构里,ruoyi-modules是存放业务模块的位置。

    ruoyi-whletest就是新增的业务。

    新增业务模块并配置步骤:

    1. 在ruoyi-modules下,右键-new-Module,使用assistant或者initial初始化模块,填写项目描述如下

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    (2)修改依赖和配置文件

    • 项目结构新增ruoyi-whaletset如下,删除多余的模块 ,最后如下。

    在这里插入图片描述

    • 需要修改whaletest模块下的pom.xml,打开ruoyi-modules-system的系统模块的pom.xml,将内容复制到ruoyi-whaletest下的pom文件,修改artifactId和description如下,其他不变。
    <artifactId>ruoyi-whaletestartifactId>
    
    <description>
        ruoyi-whaletest系统模块
    description>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    pom文件代码内容如下:

    
    <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    		 xmlns="http://maven.apache.org/POM/4.0.0"
    		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    	<parent>
    		<groupId>com.ruoyigroupId>
    		<artifactId>ruoyi-modulesartifactId>
    		<version>3.5.0version>
    	parent>
    	<modelVersion>4.0.0modelVersion>
     
    	<artifactId>ruoyi-whaletestartifactId>
     
    	<description>
    		ruoyi-whaletest模块
    	description>
     
    	<dependencies>
     
    		
    		<dependency>
    			<groupId>com.alibaba.cloudgroupId>
    			<artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
    		dependency>
     
    		
    		<dependency>
    			<groupId>com.alibaba.cloudgroupId>
    			<artifactId>spring-cloud-starter-alibaba-nacos-configartifactId>
    		dependency>
     
    		
    		<dependency>
    			<groupId>com.alibaba.cloudgroupId>
    			<artifactId>spring-cloud-starter-alibaba-sentinelartifactId>
    		dependency>
     
    		
    		<dependency>
    			<groupId>org.springframework.bootgroupId>
    			<artifactId>spring-boot-starter-actuatorartifactId>
    		dependency>
     
    		
    		<dependency>
    			<groupId>io.springfoxgroupId>
    			<artifactId>springfox-swagger-uiartifactId>
    			<version>${swagger.fox.version}version>
    		dependency>
     
    		
    		<dependency>
    			<groupId>mysqlgroupId>
    			<artifactId>mysql-connector-javaartifactId>
    			<version>8.0.22version>
    		dependency>
     
    		
    		<dependency>
    			<groupId>com.ruoyigroupId>
    			<artifactId>ruoyi-common-datasourceartifactId>
    		dependency>
     
    		
    		<dependency>
    			<groupId>com.ruoyigroupId>
    			<artifactId>ruoyi-common-datascopeartifactId>
    		dependency>
     
    		
    		<dependency>
    			<groupId>com.ruoyigroupId>
    			<artifactId>ruoyi-common-logartifactId>
    		dependency>
     
    		
    		<dependency>
    			<groupId>com.ruoyigroupId>
    			<artifactId>ruoyi-common-swaggerartifactId>
    		dependency>
     
    	dependencies>
     
    	<build>
    		<finalName>${project.artifactId}finalName>
    		<plugins>
    			<plugin>
    				<groupId>org.springframework.bootgroupId>
    				<artifactId>spring-boot-maven-pluginartifactId>
    				<executions>
    					<execution>
    						<goals>
    							<goal>repackagegoal>
    						goals>
    					execution>
    				executions>
    			plugin>
    		plugins>
    	build>
     
    project>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • ruoyi-modules模块中添加子模块,这个系统自动添加进去

    在这里插入图片描述

    • 复制ruoyi-system的resources文件夹下的banner.txt,bootstrap.yml,logback.xml文件到ruoyi-whaletest模块

    在这里插入图片描述

    • 修改banner.txt.修改ruoyi system文字为ruoyi-whale模块
    Spring Boot Version: ${spring-boot.version}
    Spring Application Name: ${spring.application.name}
    ==========ruoyi-whale模块=====
    
    • 1
    • 2
    • 3
    • 修改bootstrap.yml的端口号为9205,应用名称ruoyi-whaletest
    # Tomcat
    server:
      port: 9205
    
    # Spring
    spring: 
      application:
        # 应用名称
        name: ruoyi-whaletest
      profiles:
        # 环境配置
        active: dev
      cloud:
        nacos:
          discovery:
            # 服务注册地址
            server-addr: 127.0.0.1:8848
          config:
            # 配置中心地址
            server-addr: 127.0.0.1:8848
            # 配置文件格式
            file-extension: yml
            # 共享配置
            shared-configs:
              - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    (3)修改logback.xml中日志存放路径为:logs/ruoyi-whaletest。

    
    <configuration scan="true" scanPeriod="60 seconds" debug="false">
        
       <property name="log.path" value="logs/ruoyi-whaletest" />
       
       <property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
    
        
       <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
          <encoder>
             <pattern>${log.pattern}pattern>
          encoder>
       appender>
    
        
       <appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
           <file>${log.path}/info.logfile>
            
          <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                
             <fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.logfileNamePattern>
             
             <maxHistory>60maxHistory>
          rollingPolicy>
          <encoder>
             <pattern>${log.pattern}pattern>
          encoder>
          <filter class="ch.qos.logback.classic.filter.LevelFilter">
                
                <level>INFOlevel>
                
                <onMatch>ACCEPTonMatch>
                
                <onMismatch>DENYonMismatch>
            filter>
       appender>
    
        <appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
           <file>${log.path}/error.logfile>
            
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                
                <fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.logfileNamePattern>
             
             <maxHistory>60maxHistory>
            rollingPolicy>
            <encoder>
                <pattern>${log.pattern}pattern>
            encoder>
            <filter class="ch.qos.logback.classic.filter.LevelFilter">
                
                <level>ERRORlevel>
             
                <onMatch>ACCEPTonMatch>
             
                <onMismatch>DENYonMismatch>
            filter>
        appender>
    
        
       <logger name="com.ruoyi" level="info" />
       
       <logger name="org.springframework" level="warn" />
    
       <root level="info">
          <appender-ref ref="console" />
       root>
       
       
        <root level="info">
            <appender-ref ref="file_info" />
            <appender-ref ref="file_error" />
        root>
    configuration>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 配置nacos

    (1)登录Nacos配置中心,找到配置列表,选择ruoyi-system-dev.yml,点击克隆,并更改Data Id 为ruoyi-whaletest-dev.yml. 点击开始克隆

    在这里插入图片描述

    (2)修改ruoyi-whaletest-dev.yml中typeAliasesPackage搜索包名为: com.ruoyi.whaletest

    在这里插入图片描述

    (3)修改ruoyi-gateway-dev.yml网管的配置文件,新增whaletest模块

    新建业务的配置

       # whaletest模块
      - id: ruoyi-whaletest
          uri: lb://ruoyi-whaletest
          predicates:
            - Path=/whaletest/**
          filters:
            - StripPrefix=1
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    完整内容如下:

    spring:
      redis:
        host: localhost
        port: 6379
        password: 
      cloud:
        gateway:
          discovery:
            locator:
              lowerCaseServiceId: true
              enabled: true
          routes:
            # 认证中心
            - id: ruoyi-auth
              uri: lb://ruoyi-auth
              predicates:
                - Path=/auth/**
              filters:
                # 验证码处理
                - CacheRequestFilter
                - ValidateCodeFilter
                - StripPrefix=1
            # 代码生成
            - id: ruoyi-gen
              uri: lb://ruoyi-gen
              predicates:
                - Path=/code/**
              filters:
                - StripPrefix=1
            # 定时任务
            - id: ruoyi-job
              uri: lb://ruoyi-job
              predicates:
                - Path=/schedule/**
              filters:
                - StripPrefix=1
            # 系统模块
            - id: ruoyi-system
              uri: lb://ruoyi-system
              predicates:
                - Path=/system/**
              filters:
                - StripPrefix=1
            # 文件服务
            - id: ruoyi-file
              uri: lb://ruoyi-file
              predicates:
                - Path=/file/**
              filters:
                - StripPrefix=1
             # whaletest模块
            - id: ruoyi-whaletest
              uri: lb://ruoyi-whaletest
              predicates:
                - Path=/whaletest/**
              filters:
                - StripPrefix=1
     
    # 不校验白名单
    ignore:
      whites:
        - /auth/logout
        - /auth/login
        - /*/v2/api-docs
        - /csrf
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65

    更改完之后点击发布。

    • 修改ruoyi-whale的应用WhaleApplication.java.参照RuoYiSystemApplication,如下。
    /**
     * whaletest模块
     *
     * @author whale
     */
    @EnableCustomConfig
    @EnableCustomSwagger2
    @EnableRyFeignClients
    @SpringBootApplication
    public class WhaletestApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(WhaletestApplication.class, args);
            System.out.println("(♥◠‿◠)ノ゙  Whaletes模块启动成功   ლ(´ڡ`ლ)゙  \n" +
                    " .-------.       ____     __        \n" +
                    " |  _ _   \\      \\   \\   /  /    \n" +
                    " | ( ' )  |       \\  _. /  '       \n" +
                    " |(_ o _) /        _( )_ .'         \n" +
                    " | (_,_).' __  ___(_ o _)'          \n" +
                    " |  |\\ \\  |  ||   |(_,_)'         \n" +
                    " |  | \\ `'   /|   `-'  /           \n" +
                    " |  |  \\    /  \\      /           \n" +
                    " ''-'   `'-'    `-..-'              ");
        }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    (3)代码自动生成

    • 代码生成

    在这里插入图片描述

    • 新建菜单

    在这里插入图片描述

    在这里插入图片描述

    • 在ruoyi-whaletest模块下导入模块

    在这里插入图片描述

    在这里插入图片描述

    (4)启动项目

    • 依次找到ruoyi-gateway、ruoyi-auth、ruoyi-system、ruoyi-whaletest的启动类去启动,

    注意启动顺序。网管模块和认证模块要在系统模块和代码生成模块之前。

    在这里插入图片描述

    • 启动前端

    在这里插入图片描述

    • 访问项目

    在这里插入图片描述

  • 相关阅读:
    Adobe Premiere基础-常用的视频特效(十五)
    电脑文件自动备份到u盘,怎么实现?
    Flutter Widget 如何启用和屏蔽点击事件
    把文件上传到Gitee的详细步骤
    REST风格
    网页被劫持跳转怎么办?发布网修复方法
    基于人工势场法的二维平面内无人机的路径规划的matlab仿真,并通过对势场法改进避免了无人机陷入极值的问题
    猿创征文|Python快速刷题网站——牛客网 数据分析篇(十二)
    matlab自定义添加设置工具箱
    Flutter高仿微信-第35篇-单聊-视频通话
  • 原文地址:https://blog.csdn.net/hcz666/article/details/126039365