若依使用教程
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
},