我是土豆灬啊 2022-04-19 17:53 采纳率: 0%
浏览 216

今天自己测试了一下,往redis中存数据,代码没有报错,为什么redis中key乱码且看不到值,求解


package com.service;

public interface StudentService {

    void put(String key, String value);
}
package com.service.impl;

import com.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    @Override
    public void put(String key, String value) {

        redisTemplate.opsForValue().set(key,value);
    }
}
package com.web;

import com.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class StudentController {

    @Autowired
    private StudentService studentService;

    @RequestMapping(value = "/put")
    @ResponseBody
    public Object put(String key,String value){

        studentService.put(key,value);
        return "值已成功放入redis";
    }

}

img

  • 写回答

4条回答 默认 最新

  • 小小鱼儿小小林 全栈领域优质创作者 2022-04-19 17:58
    关注

    你这个key和value是不是前端传的,你试一下在代码中写死key和value,看下存进去会不会变成乱码,如果不会,说明是前后端传值造成的,如果不会,再排查原因

    评论

报告相同问题?

问题事件

  • 创建了问题 4月19日

悬赏问题

  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题