在我的控制器中,输入一个值 MySQL
数据库变成了 ModelAndView object
有一个单独的程序更新表和 MVC 应该抓住该值,因此没有表格来更新该表。
当。。。的时候 表已更新,当我 在浏览器上点击刷新,值不会在页面上更新。
调节器
@SuppressWarnings("unchecked")
@Secured({ "ROLE_USER", "ROLE_ADMIN" })
@RequestMapping(value = { "/", "/welcome" }, method = RequestMethod.GET)
public ModelAndView defaultPage(@ModelAttribute("user") User user) {
Collection<SimpleGrantedAuthority> authorities = (Collection<SimpleGrantedAuthority>) SecurityContextHolder
.getContext().getAuthentication().getAuthorities();
ModelAndView view = new ModelAndView("/hello");
// Redirects to admin page if user has admin role
if (authorities.toString().contains("ROLE_ADMIN")) {
return new ModelAndView("redirect:/admin");
}
/////
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String userName = auth.getName();
User userInfo = userDAO.getUserInfo(userName);
System.out.println("Here's the thing " + userInfo.getLastname() + " " + userInfo.getUserDetails());
Details details = userDAO.getDetailsInfo(userInfo.getUserDetails().getLastname(),
userInfo.getUserDetails().getPostcode());
Plugs plugs = userDAO.getPlugInfo(details.getMacAddress());
String json = plugs.getJson();
JSONObject obj = new JSONObject(json); //this is the value that is not updating
String name = obj.getJSONObject("meta").getJSONObject("locate").getString("value");
System.out.println(name);
view.addObject("json", obj);
return view;
}
我知道这很受鄙视,但我把这个值放进去了 的JavaScript。
喜欢这个:
<c:set var="json" value="${json}"/>
var __data__ = ${json};
为什么MVC在更新数据库时不会显示正确的值?
我希望它在刷新时更新
编辑:我已禁用缓存和清除缓存仍有问题。有帮助吗?