不用记录,作者的文档太好了,没必要摘抄,直接阅读作者的文档即可,关键是后期的具体实现
org.springframework.boot
spring-boot-starter-web
org.projectlombok
lombok
org.springframework.boot
spring-boot-devtools
runtime
true
org.webjars
bootstrap
4.4.1
org.webjars
jquery
3.4.1
org.webjars
webjars-locator
0.36
org.apache.commons
commons-lang3
1. mysql
mysql
mysql-connector-java
spring:
datasource:
url: jdbc:mysql://localhost:3306/web-test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
2. jpa
org.springframework.boot
spring-boot-starter-data-jpa
spring:
jpa:
properties:
hibernate:
hbm2ddl.auto: update
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
show-sql: true
3. thymeleaf
org.springframework.boot
spring-boot-starter-thymeleaf
spring:
thymeleaf:
cache: false
check-template: true
check-template-location: true
servlet.content-type: text/html
encoding: utf-8
mode: HTML
prefix: classpath:/templates/
suffix: .html
4. spring-boot log配置
logging:
file:
path: /user/local/log
level:
com.example.demo: INFO
org.springframework: DEBUG
org.hibernate: Error
org.springframework.boot.autoconfigure: ERROR # 当出现error时显示报告
5. springboot-redis配置
org.springframework.boot
spring-boot-starter-data-redis
org.apache.commons
commons-pool2
spring:
redis:
database: 0 # redis索引默认为0
host: localhost
port: 6379
password: # 默认为空
lettuce:
pool:
max-active: 8
max-idle: 8
max-wait: -1ms
min-idle: 0
@Configuration
@ConditionalOnClass(RedisOperations.class)
@EnableConfigurationProperties(RedisProperties.class)
@Import({ LettuceConnectionConfiguration.class, JedisConnectionConfiguration.class })
public class RedisAutoConfiguration {
@Bean
@ConditionalOnMissingBean(name = "redisTemplate")
public RedisTemplate
Redis 数据类型
特别注意:void set(K key, V value, long timeout, TimeUnit unit); 有失效时间一说
6. Redis-Session
org.springframework.session
spring-session-data-redis
@Configuration
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 86400*30)
public class SessionConfig {
}
7. mybatis
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.1.1
#{}与${}
// This example creates a prepared statement, something like select * from teacher where name = ?; @Select("Select * from teacher where name = #{name}") Teacher selectTeachForGivenName(@Param("name") String name); // This example creates n inlined statement, something like select * from teacher where name = 'someName'; @Select("Select * from teacher where name = '${name}'") Teacher selectTeachForGivenName(@Param("name") String name);
两种方式: (指定别名:
mybatis:
type-aliases-package: model
注解版与配置版
1) 注解版
例如:
@Select("select * from user")
@Results({
@Result(property = "email",column = "email"),
@Result(property = "username",column = "username"),
@Result(property = "pwd",column = "pwd")
})
List getAll();
2) 配置版
mybatis:
config-location: classpath:mybatis/mybatis-config.xml
mapper-locations: classpath:mybatis/mapper/*.xml
mybatis-config.xml
UserMapper.xml
id, email, username, pwd
INSERT INTO
user
(email,username,pwd)
VALUES
(#{email}, #{username}, #{pwd})
UPDATE
users
SET
email= #{email},
username= #{username},
pwd= #{pwd},
WHERE
id = #{id}
DELETE FROM
user
WHERE
id =#{id}
mybatis多数据源:连接两个数据库
其中配置关键: @Primary指定主数据源
@Configuration
@MapperScan(basePackages = "com.example.demo.mapper.test1",sqlSessionTemplateRef = "ds1SqlSessionTemplateRef")
public class MybatisDS1Config {
// 主数据源配置 ds1数据源
@Primary
@Bean(name = "ds1DataSourceProperties")
@ConfigurationProperties(prefix = "spring.datasource.ds1")
public DataSourceProperties ds1DataSourceProperties() {
return new DataSourceProperties();
}
// 主数据源 ds1数据源
@Primary
@Bean(name = "ds1DataSource")
public DataSource ds1DataSource(@Qualifier("ds1DataSourceProperties") DataSourceProperties dataSourceProperties) {
return dataSourceProperties.initializeDataSourceBuilder().build();
}
// 主数据源 ds1数据源
@Primary
@Bean("ds1SqlSessionFactory")
public SqlSessionFactory ds1SqlSessionFactory(@Qualifier("ds1DataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean sqlSessionFactory = new SqlSessionFactoryBean();
sqlSessionFactory.setDataSource(dataSource);
sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().
getResources("classpath*:com/example/demo/mapper/**/*.xml"));
return sqlSessionFactory.getObject();
}
@Primary
@Bean(name = "ds1TransactionManager")
public DataSourceTransactionManager ds1TransactionManager(@Qualifier("ds1DataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Primary
@Bean(name = "ds1SqlSessionTemplate")
public SqlSessionTemplate ds1SqlSessionTemplate(@Qualifier("ds1SqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
8. RabbitMQ
win10安装:Erlang与RabbitMQ安装时版本需要对应
了解:
依赖:
org.springframework.boot
spring-boot-starter-amqp
spring:
application.name: Spring-boot-rabbitmq
rabbitmq:
host: 127.0.0.1
port: 5672
username: guest
password: guest
9. 定时任务:SchedulerTask
org.springframework.boot
spring-boot-starter
cron="*/6 * * * * ?" ============== fixedRate = 6000 每隔6s打印
10. 邮件服务
org.springframework.boot
spring-boot-starter-mail
spring:
mail:
host: smtp.qq.com
username: [email protected]
password: ydciuraeoxbrbadj
protocol: smtp
properties:
mail:
smtp:
socketFactory:
class: javax.net.ssl.SSLSocketFactory
port: 465
auth: true
starttls:
enable: true
required: true
ps:邮件的发送者----mailSender.setFrom("发送者邮箱")
11. mongodb 默认没有密码
org.springframework.boot
spring-boot-starter-data-mongodb
2.2.5.RELEASE
spring:
data:
mongodb:
uri: mongodb
使用时要先创建集合(数据库)
12. shiro
摘抄自"纯洁的微笑的springboot笔记"
shiro功能: 较spring security更加简洁
shiro架构主要理念:
13. upload
spring:
servlet:
multipart:
14. FastDFS 文件分布式文件系统
1) win10 开启tracker服务
docker run -dti --network=host --name tracker -v /var/fdfs/tracker:/var/fdfs delron/fastdfs tracker
2) storage服务
docker run -dti --network=host --name storage -e TRACKER_SERVER=192.168.0.104:22122 -v /var/fdfs/storage:/var/fdfs delron/fastdfs storage
14. actuator
org.springframework.boot
spring-boot-starter-actuator
info:
app:
name: spring-boot-actuator
version: 1.0.0
test: test
management:
endpoints:
web:
exposure:
include: "*"
base-path: /actuator
endpoint:
health:
show-details: always
shutdown:
enabled: true
localhost:8080/actuator/info
输出:
{"app":{"name":"spring-boot-actuator","version":"1.0.0","test":"test"}}
15. admin
server端与client端
server端:
de.codecentric
spring-boot-admin-starter-server
2.2.1
server:
port: 8000
localhost:8000/ 启动server
client端:
de.codecentric
spring-boot-admin-starter-client
2.2.1
spring:
application:
name: Admin Client
boot:
admin:
client:
url: http://localhost:8000
management:
endpoints:
web:
exposure:
include: "*"
server:
port: 8081
server会监管client
16. docker-nginx-mysql
nginx win10:https://blog.csdn.net/u010417597/article/details/85316714 使用cmd(获取管理员权限)
1. MD5Util
public class MD5Util {
public static String encrypt(String dataStr) {
try {
MessageDigest m = MessageDigest.getInstance("MD5");
m.update(dataStr.getBytes("UTF8"));
byte s[] = m.digest();
String result = "";
for (int i = 0; i < s.length; i++) {
result += Integer.toHexString((0x000000FF & s[i]) | 0xFFFFFF00)
.substring(6);
}
return result;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
2. userID加密类:Des3EncryptionUtil
3. Base64编码类: Base64
4. 资源过滤配置类:SecurityConfig