目录
一、启动热部署
二、配置高级
三、常用 计量单位
四、开启数据校验
五、测试
第一种web环境测试
第二种web环境测试
编辑
第三种web环境测试
第四种web环境测试
第五种web环境测试
六、数据层解决方案
1、SQL
七、NoSQL(redis)
1、Redis
编辑
2、MonggoDB
3、ES
八、整合第三方技术
1、缓存
2、手机验证码案例
SMSCodeController
实体类SMSCode
业务层SMSCodeService和SMSCodeServiceImpl
工具类CodeUtils
3、变更缓存供应商Ehcache
2、Redis编辑
2、memcached
3、jetcache
4、j2cache
九、定时任务
1、Quartz
2、Task
十、SpringBoot整合JavaMail
一、启动热部署
二、配置高级
三、常用 计量单位
四、开启数据校验
如果爆红,直接下载导入
五、测试
第一种web环境测试
第二种web环境测试
第三种web环境测试
第四种web环境测试
第五种web环境测试
六、数据层解决方案
1、SQL
七、NoSQL(redis)
1、Redis
2、MonggoDB
db.getCollection("book").find()
//添加数据(文档)
db.book.save({"name":"springboot",type:"springboot"})
//查询
db.book.find({type:"springboot"})
//删除
db.book.remove({type:"springboot"})
//修改操作
db.book.update({name:"springboot"},{$set:{name:"springboot2"}})
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.10</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>2.4.4</version>
</dependency>
3、ES
八、整合第三方技术
1、缓存
2、手机验证码案例
SMSCodeController
package com.example.controller;
import com.example.domain.SMSCode;
import com.example.service.SMSCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @date :Created in 2023/1/2 14:08
* @description:
* @modified By:
* @version:
*/
@RestController
@RequestMapping("/sms")
public class SMSCodeController {
@Autowired
private SMSCodeService smsCodeService;
@GetMapping
public String getCode(String tele){
String code = smsCodeService.sendCodeToSMS(tele);
return code;
}
@PostMapping
public boolean checkCode(SMSCode smsCode){
return smsCodeService.checkCode(smsCode);
}
}
实体类SMSCode
package com.example.domain;
import lombok.Data;
/**
* @date :Created in 2023/1/2 14:06
* @description:
* @modified By:
* @version:
*/
@Data
public class SMSCode {
private String tele;
private String code;
}
业务层SMSCodeService和SMSCodeServiceImpl
package com.example.service;
import com.example.domain.SMSCode;
/**
* @date :Created in 2023/1/2 14:07
* @description:
* @modified By:
* @version:
*/
public interface SMSCodeService {
public String sendCodeToSMS(String tele);
public boolean checkCode(SMSCode smsCode);
}
package com.example.service.impl;
import com.example.domain.SMSCode;
import com.example.service.SMSCodeService;
import com.example.utils.CodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
/**
* @date :Created in 2023/1/2 14:08
* @description:
* @modified By:
* @version:
*/
@Service
public class SMSCodeServiceImpl implements SMSCodeService {
@Autowired
private CodeUtils codeUtils;
@Override
// @Cacheable(value = "smsCode",key = "#tele")
@CachePut(value = "smsCode",key = "#tele")
public String sendCodeToSMS(String tele) {
String code = codeUtils.generator(tele);
return code;
}
@Override
public boolean checkCode(SMSCode smsCode) {
// 取出内存中的验证码与传递过来的验证码比对,如果相同,返回true
String code = smsCode.getCode();
String cacheCode = codeUtils.get(smsCode.getTele());
return code.equals(cacheCode);
}
}
工具类CodeUtils
package com.example.utils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
/**
* @date :Created in 2023/1/2 14:11
* @description:
* @modified By:
* @version:
*/
@Component
public class CodeUtils {
private String [] patch = {"000000","00000","0000","000","00","0",""};
public String generator(String tele){
int hash = tele.hashCode();
int encryption = 2020666;
long result = hash ^ encryption;
long nowTime = System.currentTimeMillis();
result = result ^ nowTime;
long code = result % 1000000;
code = code<0?-code:code;
String codeStr = code+"";
int len = codeStr.length();
return patch[len] + codeStr;
}
@Cacheable (value = "smsCode",key = "#tele")
public String get(String tele){
return null;
}
// public static void main(String[] args) {
// System.out.println(new CodeUtils().generator("15975976827"));
// }
}
3、变更缓存供应商Ehcache
2、Redis
2、memcached
3、jetcache
4、j2cache
九、定时任务
1、Quartz
2、Task