若依使用教程
若依使用教程
1.gitee上下载代码,git clone 或者下载zip格式代码
前端(ry-ui):
1.保证电脑上已经安装nodejs。在项目目录下打开命令行,输入npm install,安装依赖文件。
2.npm run dev 启动
后端(ry):
1.使用intellij idea软件打开项目。打开->Build+Tools -> Maven 设置仓库地址为本地仓库(mac:/usr/lcoal/maven),配置users seetings file (/usr/local/maven/conf/settings.xml) / local repository(/usr/local/repository)
2.更新maven仓库
3.修改logback.xml 日志存放地址
4.打开启动redis-server。(mac :/usr/local/bin/redis-server )
5.启动若依
2.若依模块添加
2.1创建数据库
CREATE TABLE wb_pro(
id INT NOT NULL AUTO_INCREMENT COMMENT '乐观锁' ,
CREATED_BY VARCHAR(32) COMMENT '创建人' ,
CREATED_TIME DATETIME COMMENT '创建时间' ,
UPDATED_BY VARCHAR(32) COMMENT '更新人' ,
UPDATED_TIME DATETIME COMMENT '更新时间' ,
pro_name VARCHAR(32) COMMENT '专业名称' ,
object_id VARCHAR(32) COMMENT '对应的英文名称' ,
PRIMARY KEY (id)
)
2.2在管理系统菜单栏 --》系统工具--〉代码生成中,找到wb_pro表,进行导入。
2.3编辑wb_pro表
2.3.1修改生成包路径 :com.ruoyi.myexam
2.3.2修改生成模块名 :myexam
2.3.3修改 生成功能名:专业名称
2.3.4修改表描述:专业名称表
2.3.5修改上级菜单:我的考试(如果没有,可事先在菜单栏中添加)
2.4点击生成代码
2.4.1运行生成的sql文件,把相关的菜单添加到导航栏中
2.5 在项目中添加myexam模块。
2.5.1把生成的文件复制到项目对应的模块中,注意java项目中的controller文件夹要复制到ruoyi-admin模块的web文件夹下面。
重新启动ry 和 ry-ui项目
3.编写对外接口
3.1编写接口代码
@RestController
@RequestMapping("/myexam/pro")
public class WbProController extends BaseController
{
@Autowired
private IWbProService wbProService;
/**
* 查询专业名称列表
*/
@GetMapping("/mylist")
public TableDataInfo mylist(WbPro wbPro)
{
startPage();
List<WbPro> list = wbProService.selectWbProList(wbPro);
System.out.println(list+"测试数据类型。。。。");
return getDataTable(list);
}
}
3.2修改匿名访问接口
//package com.ruoyi.framework.config;
//在此文件下修改:ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
//示例:
//我的考试
.antMatchers("/myexam/pro/mylist").anonymous()
项目启动后访问:http://localhost:9090/myexam/pro/mylist,即可得到查询数据如下:
{
total: 2,
rows: [
{
searchValue: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: null,
params: { },
id: 1,
createdBy: "bingo",
createdTime: "2020-11-03",
updatedBy: "bingo",
updatedTime: "2020-11-02",
proName: "公共场所",
objectId: "publi"
},
{
searchValue: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: null,
params: { },
id: 2,
createdBy: null,
createdTime: null,
updatedBy: null,
updatedTime: null,
proName: "生活饮用水",
objectId: "water"
}
],
code: 200,
msg: "查询成功",
preUrl: null
}
3.3 配置SSL访问
3.3.1下载jks文件和keystorePass.txt文件
3.3.2配置application.yml文件
# 项目相关配置
ruoyi:
... #省略
port:
http: 9090
# 开发环境配置
server:
# 服务器的HTTP端口,默认为8080
port: 8443
... #省略
#配置https访问
ssl:
key-store: classpath:www.ctlaowang.xyz.jks
key-store-password: 6bf3x84tq55599 #密码在keystorePass.txt文件中
key-store-type: JKS
3.3.3配置类
package com.ruoyi.web.core.config;
import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.coyote.http11.Http11NioProtocol;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
//在开启ssl时启用配置
@Configuration
public class SSLConfig {
@Value("${ruoyi.port.http}")
private int serverPortHttp;
@Value("${server.port}")
private int serverPortHttps;
@Bean
public ServletWebServerFactory servletWebServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection securityCollection = new SecurityCollection();
securityCollection.addPattern("/*");
securityConstraint.addCollection(securityCollection);
context.addConstraint(securityConstraint);
}
};
factory.addAdditionalTomcatConnectors(redirectConnector());
return factory;
}
private Connector redirectConnector() {
Connector connector = new Connector(Http11NioProtocol.class.getName());
connector.setScheme("http");
connector.setPort(serverPortHttp);
connector.setSecure(false);
connector.setRedirectPort(serverPortHttps);
return connector;
}
}
此时本地访问http😕/localhost:9090/myexam/pro/mylist 会自动跳转到https😕/localhost:8443/myexam/pro/mylist
3.3.4远程访问配置
注意将数据库数据与远程数据库保持一致
3.3.4.1nginx配置文件路径:
/etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
#配置自己的配置文件路径
include /etc/nginx/conf.d/*.conf;
}
/etc/nginx/conf.d/my.conf
server {
listen 90;
server_name localhost;
location / {
root /usr/local/www/ry;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /prod-api/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://localhost:8443/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
nginx命令:
重启:nginx -s reload
3.3.4.2将ruoyi-admin.jar包放入 /usr/local/www 目录中, 后台启动jar包
# 查看监听的端口
netstat -lnpt
# 杀掉java进程
kill -9 端口号
运行:nohup java -jar ruo yi-admin.jar &
出现错误:nohup: ignoring input and appending output to ‘nohup.out’
# 将 nohup 的日志输出到 /dev/null,这个目录会让所有到它这的信息自动消失
后台启动方法:nohup java -jar ruo yi-admin.jar > /dev/null 2> /dev/null &
3.3.4.3将dist文件中的前端数据放入 /usr/local/www 目录中
//注意打包前配置 vue.config.js 文件,端口做相应的修改
// webpack-dev-server 相关配置
devServer: {
host: '0.0.0.0',
port: port,
open: true,
proxy: {
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API]: {
target: `https://localhost:8443`,
changeOrigin: true,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
}
}
},
disableHostCheck: true
},