<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ### 一.引入依賴 ~~~ <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> ~~~ ***** ### 二.配置redis連接信息 ~~~ # redis spring: redis: host: 127.0.0.1 port: 6379 ~~~ ### 三.測試 ~~~ package com.youworker; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.youworker.domain.User; import com.youworker.repository.UserRepository; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; import java.util.List; @RunWith(SpringRunner.class) @SpringBootTest public class RedisTest { @Resource private RedisTemplate<String, String> redisTemplate; @Autowired private UserRepository userRepository; @Test public void index() { //將list集合轉換成json格式的字符串,使用jackson進行轉換 ObjectMapper objectMapper = new ObjectMapper(); //1.從redis中獲得得數據,數據的形式json字符串 String userListJson = redisTemplate.boundValueOps("user.findAll").get(); //2.判斷redis中是否存在數據 if (null == userListJson) { //3.不存在數據則從數據庫查詢 List<User> all = userRepository.findAll(); //4.將查詢出的數據存儲到redis緩存中 try { userListJson = objectMapper.writeValueAsString(all); redisTemplate.boundValueOps("user.findAll").set(userListJson); System.out.println("===========從數據庫中獲得user的數據==============="); } catch (JsonProcessingException e) { e.printStackTrace(); } } else { System.out.println("===========從redis緩存中獲得user的數據==============="); } //5.將數據在控制臺打印 System.out.println(userListJson); //json轉 對象 User user[] = new User[0]; try { user = objectMapper.readValue(userListJson, User[].class); } catch (JsonProcessingException e) { e.printStackTrace(); } System.out.println("json轉換list"); for (User user1:user){ System.out.println(user1); System.out.println(user1.getUsername()); } } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看