(exclude = DataSourceAutoConfiguration.class)
DynamicDataSourceAutoConfiguration
(exclude = DataSourceAutoConfiguration.class)
DynamicDataSourceAutoConfiguration
使用dynamic-datasource-spring-boot-starter,并用@DS指定数据源
SpringBoot 配合 druid作为数据库连接池 时需要注意的一点
使用dynamic-datasource-spring-boot-starter做多数据源及源码分析
需要配置master作为默认数据源,否则会报,请检查primary默认数据库设置。
[Spring Boot 排除自动配置的 4 种方法,关键时刻很有用!]
@RequestBody和@RequestParam注解使用
1 | import org.springframework.beans.factory.annotation.Value; |
@Value
static
https://blog.csdn.net/ZYC88888/article/details/87863038
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘pubApiPush’: Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder ‘group_url’ in value “${group_url}”
group_url: [[查看结果|http://wolf.waimai.dev.sankuai.com/group/hubble/page/dolphinManage]]
| %20 | 空格 |
|---|---|
| %21 | ! |
| %23 | # |
| %24 | $ |
| %25 | % |
| %26 | & |
| %27 | ’ |
| %28 | ( |
| %29 | ) |
| %2A | * |
| %2B | + |
| %2C | , |
| %2E | . |
| %2F | / |
| %3A | : |
| %3B | ; |
| %3D | = |
| %3F | ? |
| %40 | @ |
| %5B | [ |
| %5C | / |
| %5D | ] |
修复方案:
如果拼接参数是SQL的查询参数都可以通过将mybatis配置文件中的 $ 改为 #,来解决
替换规则如下:
1.将 WHERE some_field = ‘${变量}’ 替换为 WHERE some_field = #{param}
2.将 like ‘%${变量}%’ 替换为 like concat(‘%’, #{变量}, ‘%’)
3.将 like concat(‘%’, ${变量}, ‘%’) 替换成 like concat(‘%’, #{变量}, ‘%’)
4.将 WHERE some_field IN (${变量}) 替换为
WHERE some_field IN
#{item}
对于拼接的变量不是SQL参数的,而是字段名、表名的情况,可以使用安全SDK检查输入是否是合法的标识符。
1.pom 引入安全SDK依赖
com.sankuai.security
sec-sdk
${尽可能最新版本}
\2. 代码中检查输入的变量的值是否是合法的标识符。
String sortName = req.getParameter(“sortName”);
if (sortName != null && !SecSdk.isValidSqlIdentifier(sortName)) {
// 危险,可能有SQL注入,
// return or throw exception
}
参考文档:
SQL注入介绍:https://sectraining.sankuai.com/?source=source-scanner/#/document/30001
安全SDK文档:https://km.sankuai.com/page/234776924
1 | switch (i) |
interface 属性为 private static final
abstract 父类中的属性,默认式private的,非private的在子类中可以使用
1 | String pattern ="dd-MMM-yy hh.mm.ss aa"; |
字符串补位
1 | "%02d".format(currentTime.getMinuteOfHour) |