📅 2022-04-02 13:58
👁️ 653
💬 0
Windows SSH免密连接Linux服务器
我们在自己电脑上需要远程连接Linux服务器时,每次都需要输入 ssh @username ip -p port
,还需要输入登录密码,过程复杂,因此准备在Windows上配置SSH免密连接Linux服务器
前提:电脑上已经存在一对SSH-Key,准备新建一对SSH-Key
1 创建SSH-Key
# 1.生产密钥 以rsa算法
C:\Users\Administrator\.ssh> ssh-keygen -t rsa -C "linux"
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\Administrator/.ssh/id_rsa): C:\Users\Administrator/.ssh/id_rsa_linux #2.填写新的地址
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\Administrator/.ssh/id_rsa_linux.
Your public key has been saved in C:\Users\Administrator/.ssh/id_rsa_linux.pub.
The key fingerprint is:
SHA256:QeTc5iTO6rhOTW1a5IfgcOw3rMPjhdCYpcrz2VPpbMg linux
The key's randomart image is:
+---[RSA 2048]----+
| .o |
| . + . |
| . = * + |
| @ O B |
| = = S.o |
| . . = Ooo |
| + ..X=. |
| + *E++ |
| .*.+o |
+----[SHA256]-----+
PS C:\Users\Administrator\.ssh>

2 将公钥拷贝到Linux服务器上(拷贝或上传)
位置:/root/.ssh

如果不存在 authorized_keys,则新建一个文件,将生成的公钥复制追加到authorized_keys中
还可以通过上传的方式,将公钥上传到服务器上:
-
使用 Git Bash ,在Windows ssh文件夹下右击打开 Git Bash 输入 ssh-copy-id root@ip -p prot
-
输入密码,后即可上传
3 Linux服务器修改SSH配置
位置:/etc/ssh/sshd_config

PermitRootLogin yes
RSAAuthentication yes
PubkeyAuthentication yes
注意:修改玩后重启SSH服务:
service ssh restart
// centos 6的命令
systemctl restart sshd
// centos 7的命令
4.在Windows ssh文件下新建config文件

内容如下:
Host name ## 自定义名称
HostName ip ## ip地址
Port port ## 端口号
User user ## 登录用户名
IdentityFile ~/.ssh/id_rsa_linux ##使用的私钥
5.测试使用
命令行中输入:ssh 自定义名称 (与上述 Host 后面定义的名称一致)

阅读更多
📅 2022-03-21 13:07
👁️ 376
💬 0
MySQL 间隔取数据
背景介绍:系统中存在一张坐标表,存取一段路线桩号的具体坐标,坐标点多且密,如果全部返回给前端,后端接口响应很慢,为了解决这个问题,准备在查询数据库的时候,间隔取出一些坐标点即可,如每十个桩号取一个即可
数据表如下:

具体实现:
SELECT
n,id,longitude,latitude
FROM
(
SELECT
@n:= @n + 1 AS n,
a.*
FROM
( SELECT * FROM biz_project_coordinates WHERE hidden = 0 AND geometry_id = "8ae4240e7c83a953017c83e07c043a91" ORDER BY origin_pile ) a,
( SELECT @n := 0 ) b
) c
WHERE
c.n % 10 = 1 // 每十条取一条
OR c.n = 1
结果:

阅读更多
📅 2022-03-21 12:45
👁️ 2207
💬 0
MySql 分组 获取每组最新的一条数据
前提:学生成绩表如下

问题描述:获取每门科目成绩最高的记录,即取出 语文成绩最高(id=3)、数学成绩最高(id=4)的两条数据
解决方案:先按成绩(grade)降序,在进行分组
注意 :DISTINCT(s.id) tid 必需
SELECT *
FROM (
SELECT DISTINCT(s.id) tid, s.* FROM `student` s
ORDER BY s.grade DESC
) t
GROUP BY t.`subject`
结果:

阅读更多
📅 2021-12-09 17:47
👁️ 873
💬 0
SpringBoot 集成 knife4j (Swagger2)
前提 :本文 spring boot版本为 2.6.1 ,knife4j 版本为:3.0.3
1、初始化项目,导入pom依赖
<!-- https://mvnrepository.com/artifact/com.github.xiaoymin/knife4j-spring-boot-starter -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
2、创建Swagger配置类
@Configuration
public class Swagger2Config {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(this.apiInfo())
.select()
// 这里可以指定扫描包的路径 或者 扫描指定的注解
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build().protocols(this.newHashSet("https","http"));
}
@SafeVarargs
private final <T> Set<T> newHashSet(T... ts) {
return ts.length > 0 ? new LinkedHashSet(Arrays.asList(ts)) : null;
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Swagger接口文档")
.description("文档描述")
.contact( new Contact("xmStudy","https://www.cnblogs.com/XiaoMingStudy1/","123@qq.com"))
.termsOfServiceUrl("")
.version("1.0")
.build();
}
}
最终项目结构图如下:

3、出现的问题
项目启动失败

4、解决问题
原因分析:在springboot 2.6.0会提示documentationPluginsBootstrapper NullPointerException,具体位置的WebMvcPatternsRequestConditionWrapper中的condition为null。原因是在springboot2.6.0中将SpringMVC 默认路径匹配策略从AntPathMatcher 更改为PathPatternParser,导致出错,解决办法是切换会原先的AntPathMatcher
解决问题:在properties中加上spring.mvc.pathmatch.matching-strategy=ant-path-matcher
5、项目正常启动,访问一下
ip为 ip:port/doc.html, 如 http://localhost:8080/doc.html#/home

6 参考连接
- Knife4j 官方文档:https://doc.xiaominfo.com/knife4j/
- Github地址:https://github.com/xiaoymin/swagger-bootstrap-ui/issues/396
- Gitee地址:https://toscode.gitee.com/xiaoym/knife4j
阅读更多
📅 2021-09-26 15:06
👁️ 270
💬 0
原样式:

看着很不爽
本文 idea 版本为:idea 2020.3.1,以下操作均基于此版本进行
解决办法
1.去除警告
Settings>Editor>Inspections>SQL>No data sources configured 和 SQL dialect detection
No data sources configured :没有配置数据源
SQL dialect detection:SQL方言检测

去除警告过后还有默写语句存在背景色

2.去除“注入语言”背景色
**Settings>Editor>Color Scheme>Code>Injected language fragement **

最终样式:

阅读更多
📅 2021-09-13 11:13
👁️ 188
💬 0
错误信息如图:

错误原因:在自定义主键是没有注明自增策略
解决办法:明确主键自增策略,比如
@Entity
@Table(name = "t_order")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Order implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String customer;
private Date orderDate;
}
扩展:Jpa GenerationType的四种类型
- TABLE :使用一个特定的数据库表格来保存主键
- SEQUENCE:根据底层数据库序列来生成主键,条件是数据库支持序列
- IDENTITY:主键由数据库自动生成,数据库设置了自增主键
- AUTO:主键由程序控制,是Jpa的默认策略,可以不写
阅读更多
📅 2021-09-13 11:02
👁️ 1032
💬 0
Springboot项目 配置数据库连接属性后,启动项目报错,错误如下:

错误原因分析:
1.连接信息配置错误
当使用properties为配置文件时,如图所示,上面的 spring.datasource.name 这种写法是错误的,应该是username,还有一种情况可以将spring.datasource.driver-class-name 改成 spring.datasource.driverClassName;

当使用yaml作为配置文件时,除了需要注意空格的情况,当用户名和密码为数字时,需要小心
如下这个配置将会报错:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false
username: root
password: 000000
这里的password为000000 ,最终获取的值是0 ,所以连接时将会报错
正确配置如下:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false
username: root
password: "000000"
2.数据库授权失败
当连接信息都配置正确的化,很有可能是数据库授权失败,所以需要进数据库对当前用户授权
阅读更多
📅 2021-09-13 10:42
👁️ 195
💬 0
新建一个Springboot项目时,当勾选了SQL相关的依赖(如引入了jpa 或MyBatis依赖),直接启动项目时报错

原因:没有配置数据库相关的属性,如 url driver 等
解决办法:在application.properties 中设置数据库链接的相关属性
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=root
阅读更多
📅 2021-09-10 09:36
👁️ 923
💬 0
使用mysql新增数据时报错,具体信息如图所示:

错误原因:
所建的表中 表名或字段名与数据库关键字冲突
解决办法
可以根据报错信息,查看错误的具体位置,找到数据库中对应的字段,查询是否与关键字(不分大小写)一样,如果一样需要进行修改
阅读更多
📅 2021-08-05 09:35
👁️ 115
💬 0
阅读更多