SpringBoot入门系列:第四篇 redis

本文介绍了SpringBoot项目中整合Redis的基本步骤,包括创建spring-boot-sample-redis工程,使用StringRedisTemplate进行字符串操作,以及利用RedisTemplate处理复杂类型的数据。详细讲解了从设置到获取数据的整个流程,并提供了相应的测试URL。
摘要由CSDN通过智能技术生成

一,准备工作,建立spring-boot-sample-redis工程

1、http://start.spring.io/

     A、Artifact中输入spring-boot-sample-redis

     B、勾选Web下的web

     C、勾选NOSQL下的Redis

2、Eclips中导入工程spring-boot-sample-redis

     A、解压快捷工程spring-boot-sample-redis到某文件夹

     B、eclips中file->import->Import Existing Maven Projects-->Select Maven projects-->finish导入工程

3、工程导入之后,文件结构如下图

4、在包com.example下建立web文件夹

5、便于测试,引入spring-boot-sample-helloworld的HelloController及配置文件logback.xml

HelloController代码为

package com.example.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

	protected static Logger logger=LoggerFactory.getLogger(HelloController.class);
	
	@RequestMapping("/")
	public String helloworld(){
		logger.debug("访问hello");
		return "Hello world!";
	}
	
	@RequestMapping("/hello/{name}")
	public String helloName(@PathVariable String name){
		logger.debug("访问helloName,Name={}",name);
		return "Hello "+name;
	}
}
logback.xml配置为

<configuration>  
    <!-- %m输出的信息,%p日志
评论 23
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值