在下面的代码片段中,我无法从 redis 中读取 (GET) 值。
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("SpringContext.xml");
User user = new User(); // java Bean
RegistrationBean bean = (RegistrationBean) applicationContext.getBean("RegistrationBean");
User user = new User();
user.setUserid("200112021");
user.setName("name1");
user.setAddress("adress sd");
bean.getRedisTemplate().opsForHash().put("A12", user.hashCode(),user);
User x = (User)bean.getRedisTemplate().opsForHash().get("A12",user.hashCode());
System.out.println(x.getName());
以上代码仅在同时使用 PUT 和 GET 时运行,但如果不使用 PUT 并且仅对特定记录使用 GET 那么我得到 NULL 值请建议?
谢谢 维杰
最佳答案
问题已解决....
我使用了 Spring MVC API。以下是代码片段
public String addcustomer(@ModelAttribute("customer")customerVO customer, ModelMap model) {//从 UI 获取客户数据
model.addAttribute("QuestionName", customer.getQuestionName());
model.addAttribute("comments", customer.getComments());
model.addAttribute("pollID", customer.getPollID());
model.addAttribute("answer", customer.getAnswers());
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("servletDispatcher-servlet.xml");
CustomerRepository customerRepository = (CustomerRepository) applicationContext.getBean("customerrepository");
customerRepository.put(customer);
System.out.println(" Step 1 output : " + customerRepository.getObjects());
关于java - 如果仅使用 GET,则无法读取 Redis 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30353690/