在以下代码段中,我无法从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值pls建议吗?
由于 维杰
答案 0 :(得分:0)
问题已解决......
我使用了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());