依赖
<dependencies>
<!-- web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- 通用池 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<!-- 通用mapper -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.0.3-beta1</version>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
配置
server:
port: 8090
spring:
datasource:
username: root
password: root
url: jdbc:mysql://127.0.0.1:3306/mysql01
redis:
host: localhost
port: 6379
timeout: 1000
jedis:
pool:
min-idle: 5
max-idle: 10
max-wait: -1
mybatis:
mapper-locations: classpath:/mybatis/mapper/*.xml
type-aliases-package: com.example.entities
# 驼峰转换
configuration:
map-underscore-to-camel-case: true
thymeleaf:
check-template: false
check-template-location: false
controller
@RestController
public class RedisController {
@Autowired
private RedisTemplate redisTemplate;
@GetMapping("/redis/get/{key}")
public Object get(@PathVariable("key") String key){
return redisTemplate.opsForValue().get(key);
}
@PostMapping("/redis/set/{key}/{value}")
public Object set(@PathVariable("key") String key,
@PathVariable("value") String value){
redisTemplate.opsForValue().set(key, value);
return "set success";
}
}
测试蒙了。。。。。。
2022-1-6补充
昨天测试一直404,原因:
启动类少了注解:@ComponentScan
先测试一下mysql连接是否成功,在springboot自带的测试类进行:
图 2测试结果:
图 3再测试一下redis连接是否成功:
图 4测试结果:
图 5测试controller接口:
图 6终于成了,菜的让自己心疼。。。。。。
网友评论