1. <dependency>
    2. <groupId>org.springframework.boot</groupId>
    3. <artifactId>spring-boot-starter-web</artifactId>
    4. </dependency>
    1. package com.example.controller;
    2. import org.springframework.beans.factory.annotation.Autowired;
    3. import org.springframework.data.redis.core.StringRedisTemplate;
    4. import org.springframework.web.bind.annotation.*;
    5. @RestController
    6. public class TestController {
    7. @Autowired
    8. StringRedisTemplate redisTemplate;
    9. @RequestMapping(value = "/index",method = RequestMethod.GET)
    10. public String index() {
    11. redisTemplate.opsForValue().increment("count",1L);
    12. String value = redisTemplate.opsForValue().get("count");
    13. return "当前网站的访问人数为:" +value;
    14. }
    15. }