抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

一切得先从我的操作说起。

在集成mybatis-plus过程中,我将 pagehelper-spring-boot-starter 拆成两个依赖包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!-- 分页插件 -->
<!-- <dependency>-->
<!-- <groupId>com.github.pagehelper</groupId>-->
<!-- <artifactId>pagehelper-spring-boot-starter</artifactId>-->
<!-- <version>1.2.5</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.4</version>
</dependency>
<!-- pagehelper 依赖 -->
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>1.0</version>
</dependency>

定义一个config类

1
2
3
4
5
6
7
8
9
10
11
12
@Component
@ConfigurationProperties(prefix = "app-config")
@Data
public class AppConfig {
public static final String USER_HEAD_IMAGE_PATTERN = "/user/header/";
@NotNull
private String userHeaderImg;
@NotNull
private String filePath;
@NotNull
private String imgUrl;
}

这样的意思是,它里面的所有字段都可以在application.properties里进行配置,数据会被注入到配置对象中,在全局中都可以使用

1
2
3
app-config.imgUrl=/home/project/website/user/header/
app-config.userHeaderImg=file:/home/project/website/user/header/
app-config.filePath=http://192.168.1.102:8096\

我的一直报 ClassNotFoundException: org.mybatis.logging.LoggerFactory,我判断肯定是mp和pagehelper冲突了,但是pagehelper已经在工程中广泛的使用了,是不可能注释掉的。找打了一篇合适的博客,照着做解决了。

主要解决方法是,把pagehelper-starter springboot启动器拆成底层的两个依赖。但是这样的话,配置就要重新配过了。

1
2
3
4
5
6
7
8
9
10
11
12
<!-- pagehelper-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</exclusion>
</exclusions>
</dependency>

然后手动添加拦截器,拦截com.github.pagehelper

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
package com.xh.sdk.springcloud.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;

@Configuration
public class MyBatisPlusConfig {

/*
* 分页插件,自动识别数据库类型
* 多租户,请参考官网【插件扩展】
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}


@Bean
ConfigurationCustomizer mybatisConfigurationCustomizer() {
return new ConfigurationCustomizer() {
@Override
public void customize(MybatisConfiguration configuration) {
configuration.addInterceptor(new com.github.pagehelper.PageInterceptor());
}
};
}

}

参考链接

解决mybatis plus 3.x 和pagehelper无法共用、包冲突问题
解决Mybatis-plus和pagehelper依赖冲突

按注解扫描包就可以做到多包扫描了

1
2
3
4
5
6
7
8
9
10
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//为当前包路径
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build();
}

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
# Properties file with JDBC-related settings.
##########
# HSQLDB #
##########
#jdbc.driverClassName=org.hsqldb.jdbcDriver
#jdbc.url=jdbc:hsqldb:hsql://localhost:9001/bookstore
#jdbc.username=sa
#jdbc.password=
###########
# MySQL 5 #
###########
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=GBK
jdbc.username=root
jdbc.password=root
##############
# PostgreSQL #
##############
#jdbc.driverClassName=org.postgresql.Driver
#jdbc.url=jdbc:postgresql://localhost/bookstore
#jdbc.username=
#jdbc.password=
##########
# Oracle #
##########
#jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
#jdbc.url=jdbc:oracle:thin:@192.168.1.250:1521:devdb
#jdbc.username=HFOSPSP
#jdbc.password=HFOSPSP
#############################
# MS SQL Server 2000 (JTDS) #
#############################
#jdbc.driverClassName=net.sourceforge.jtds.jdbc.Driver
#jdbc.url=jdbc:jtds:sqlserver://localhost:1433/bookstore
#jdbc.username=
#jdbc.password=
##################################
# MS SQL Server 2000 (Microsoft) #
##################################
#jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
#jdbc.url=jdbc:sqlserver://192.168.1.130:1433;database=ahos;user=sa;password=ahtec";
#jdbc.username=sa
#jdbc.password=ahtec
########
# ODBC #
########
#jdbc.driverClassName=sun.jdbc.odbc.JdbcOdbcDriver
#jdbc.url=jdbc:odbc:bookstore
#jdbc.username=
#jdbc.password=

参考来源

数据库几种常见的driverClassName和url

竟然还有图片服务器,真是,世界之大,无奇不有。

https://sm.ms 是一个免费的图片服务器,上传图片即可返回图片的网络url,这样就省的自己维护和搭建专门的图片服务器了。

当让你也可以你也可以自己搭建文件服务器,上传多种文件。

网址是https://sm.ms

api是https://sm.ms/doc/

参考来源

https://blog.csdn.net/weixin_41870396/article/details/95640565

环境:Windows10-64位,SpringBoot是2.1.1,内嵌Tomcat 9.0.13, 把日志级别设为Debug后,从控制台看到启动时tomcat报无法找到JNI动态链接库的错误,完整的异常栈信息如下: 12345678910111213141516171819202122232425262728293031323334org.apache.tomcat.jni.Library...

网上到处都是,就留一篇博客就行了

https://blog.csdn.net/caijunfen/article/details/81867043

在网上找到了一个写法直接将对象转map,只是能用不出错。效率上应该是挺糟糕的。

1
2
3
4
5
6
7
public static Map<String, Object> toMap(Object args) {
return Arrays.stream(BeanUtils.getPropertyDescriptors(args.getClass()))
.filter(pd -> !"class".equals(pd.getName()))
.collect(HashMap::new,
(map, pd) -> map.put(pd.getName(), ReflectionUtils.invokeMethod(pd.getReadMethod(), args)),
HashMap::putAll);
}