typecho旧链接重新跳转

typecho博客程序后台更改了永久地址,以前搜索引擎手里的旧地址打开报404

解决方案:

if ($request_uri ~* "^/article/(\d+)/?$") {
    return 301 /new-articles/$1;
}

还是chatgpt给力。。

Windows10安装RabbitMQ

   
    Windows10安装RabbitMQ
本文简略记载下艰辛安装旅程需要注意的点

1、首先需要 安装erlang
https://www.erlang.org/downloads

2、设置erlang的环境变量
变量名:

ERLANG_HOME

变量值:

你的erlang安装路径 例如:D:\tool\erl10.5

3、安装RabbitMQ https://www.rabbitmq.com/install-windows.html

4、设置环境变量
变量名:

RABBITMQ_HOME

变量值:

你的RabbitMQ安装路径 例如:D:\tool\RabbitMQ Server\rabbitmq_server-3.8.3

最后把添加的两个环境变量添加到系统path路径中

%ERLANG_HOME%\bin;%RABBITMQ_HOME%\sbin;

5、安装plugins插件 执行:

rabbitmq-plugins enable rabbitmq_management

6、启动执行

rabbitmq-server.bat
需要注意点:

工具安装路劲不能包含空格和中文

安装的erlang必须和RabbitMQ版本匹配
https://www.rabbitmq.com/which-erlang.html#supported-version-policy

springboot拦截器放行静态资源

springboot拦截器放行静态资源
# 编写一个类
实现 WebMvcConfigurer

```java
package com.my.blog.website.interceptor;
import com.my.blog.website.utils.TaleUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
* 向mvc中添加自定义组件
* Created by BlueT on 2017/3/9.
* 更换MVC配置类
*/
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Resource
private BaseInterceptor baseInterceptor;
@Resource
private IpInterceptor ipInterceptor;

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(ipInterceptor);
registry.addInterceptor(baseInterceptor);
}

/**
* 添加静态资源文件,外部可以直接访问地址
*
* @param registry
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
registry.addResourceHandler("/upload/**").addResourceLocations("file:" + TaleUtils.getUplodFilePath() + "upload/");
}
}

```

Springboot动态生成网站地图sitemap教程

发现自从换了一套博客程序后,之前搜索引擎抓取的链接都失效了,所以才有此想法采用java生成动态的网站地图。
# 步骤一 创建实体
> SiteMapVo

```java
package com.my.blog.website.modal.Vo;

import com.my.blog.website.utils.SiteMapUtils;
import org.thymeleaf.util.DateUtils;

import java.util.Date;
import java.util.Locale;

/**
* @author Jesse-liu
* @description: 网站地图entity
* @date 2020/5/7 9:09
*/
public class SiteMapVo {
/**
* url https://www.xxx.com
*/
private String loc;
/**
* 最后更新时间 yyyy-MM-dd
*/
private Date lastmod;
/**
* 更新速度 always hourly daily weekly monthly yearly never
*/
private String changefreq;
/**
* 权重 1.0 0.9 0.8
*/
private String priority;

public String getLoc() {
return loc;
}

public void setLoc(String loc) {
this.loc = loc;
}

public Date getLastmod() {
return lastmod;
}

public void setLastmod(Date lastmod) {
this.lastmod = lastmod;
}

public String getChangefreq() {
return changefreq;
}

public void setChangefreq(String changefreq) {
this.changefreq = changefreq;
}

public String getPriority() {
return priority;
}

public void setPriority(String priority) {
this.priority = priority;
}

public SiteMapVo() {

}

public SiteMapVo(String loc) {
this.loc = loc;
this.lastmod = new Date();
this.changefreq = SiteMapUtils.CHANGEFREQ_ALWAYS;
this.priority = "1.0";
}

public SiteMapVo(String loc, Date lastmod, String changefreq, String priority) {
this.loc = loc;
this.lastmod = lastmod;
this.changefreq = changefreq;
this.priority = priority;
}

@Override
/** 重写 toString 适应xml格式 */
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("

"); sb.append("" + loc + ""); sb.append("" + DateUtils.format(lastmod, "yyyy-MM-dd", Locale.SIMPLIFIED_CHINESE) + ""); sb.append("" + changefreq + ""); sb.append("" + priority + ""); sb.append("

");
return sb.toString();
}
}

```

# 步骤二 创建工具类
> SiteMapUtils

```java
package com.my.blog.website.utils;

import com.my.blog.website.constant.WebConst;
import com.my.blog.website.modal.Vo.ContentVo;
import com.my.blog.website.modal.Vo.SiteMapVo;
import com.my.blog.website.service.IContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
* @author Jesse-liu
* @description: java生成sitemap网站地图工具类
* @date 2020/5/7 10:25
*/
@Component
public class SiteMapUtils {

public final static String BEGIN_DOC = "

"; public final static String END_DOC = "

";
public final static String CHANGEFREQ_ALWAYS = "always";
public final static String CHANGEFREQ_HOURLY = "hourly";
public final static String CHANGEFREQ_DAILY = "daily";
public final static String CHANGEFREQ_WEEKLY = "weekly";
public final static String CHANGEFREQ_MONTHLY = "monthly";
public final static String CHANGEFREQ_YEARLY = "yearly";
public final static String CHANGEFREQ_NEVER = "never";

@Autowired
private IContentService contentsService;

public String getBlogSiteMap() {
StringBuffer sb = new StringBuffer();
sb.append(BEGIN_DOC);
sb.append(new SiteMapVo(WebConst.initConfig.get("site_url")));
List contentList = contentsService.findContentList();
contentList.forEach(entity -> {
sb.append(new SiteMapVo(Commons.permalink(entity), DateKit.dateFormat(Commons.fmtdate(entity.getModified(), "yyyy-MM-dd"), "yyyy-MM-dd"), CHANGEFREQ_MONTHLY, "0.9"));
});
sb.append(END_DOC);
return sb.toString();
}

public String getBzSiteMap() {
StringBuffer sb = new StringBuffer();
sb.append(BEGIN_DOC);
sb.append(new SiteMapVo(WebConst.initConfig.get("site_url")));
sb.append(END_DOC);
return sb.toString();
}
}

```
# 步骤三
> Web层添加请求控制器

```java
/**
* @return : java.lang.String
* @author Jesse-liu
* @date 2020/5/7
* @description: 动态生成网站地图sitemap
**/
@GetMapping(value = {"sitemap.xml", "sitemap"})
public void getSiteMap(HttpServletResponse response) throws IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType(MediaType.APPLICATION_XML_VALUE);
response.getWriter().append(siteMapUtils.getBlogSiteMap());
}
```

完美收工!!!

# 效果展示页面
[https://ooolo.net/sitemap.xml](https://ooolo.net/sitemap.xml)