在我的控制器中,将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 " + …Run Code Online (Sandbox Code Playgroud) 我有一个包含HTML和CSS的登录页面.它功能齐全,而且功能齐全.但是,当登录失败时,我希望登录表单动摇.我该如何让它动摇.现在,它什么也没做.
这是我的HTML/CSS/JavaScript.如果需要更多代码,请告诉我.
HTML
<div class="input">
<c:if test="${not empty error}">
<div class="error">${error}</div>
</c:if>
<c:if test="${not empty msg}">
<div class="msg">${msg}</div>
</c:if>
<div class="email">
<input type="text" name="username"
placeholder="Example@email.com"></input>
</div>
<div class="password">
<input type="password" name="password" placeholder="*********"></input>
</div>
</div>
<input class="login_btn" type="submit" name="submit" value="">
Run Code Online (Sandbox Code Playgroud)
CSS
.container .login_component .login_wrap .login_wp .input input {
width: 290px;
height: 50px;
padding-left: 20px;
font-size: 15px;
border: none;
background: transparent;
}
.container .login_component .login_wrap .login_wp .input .email {
height: 53px;
margin-top: 20px;
background:
url("http://xiilab.mynetgear.com:81/c.hwang/rems/images/login/input.png");
background-repeat: no-repeat;
background-position: center center;
}
.container …Run Code Online (Sandbox Code Playgroud) 我试图每30分钟对我的时间戳进行分组.
我希望我的结果是这样的:
2016-03-09 00:00:00
2016-03-09 00:30:00
2016-03-09 01:00:00
Run Code Online (Sandbox Code Playgroud)
相反,我的结果如下:
2016-03-09 00:00:23
2016-03-09 00:35:02
2016-03-09 01:00:03
Run Code Online (Sandbox Code Playgroud)
我正在使用的查询就是这个
SELECT timestamp
FROM a.tablename
WHERE name = 'example' AND timestamp LIKE '2016-03-09%'
GROUP BY ROUND(((60/30) * HOUR(timestamp) + FLOOR( MINUTE(timestamp) / 30)));
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到我想要的结果?我已经研究了关于SO的其他答案,而非答案的帮助
我不确定我是否足够了解该主题以正确提出问题。
无论如何,登录后,我想重定向到在 url 路径中使用用户名的 url。我怎么能做到这一点?
例如,有人使用用户名“bmarkham”登录。我想登录后重定向到 www.website.com/bmarkham
这是我的 spring-security.xml
<form-login login-page="/login" default-target-url="/welcome/"
authentication-failure-url="/login?error" username-parameter="username"
password-parameter="password" login-processing-url="/auth/login_check" />
Run Code Online (Sandbox Code Playgroud)
我已经尝试过搞砸了default-target-url,但没有任何效果。
这是我的控制器
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView login(@RequestParam(value = "error", required = false) String error,
@RequestParam(value = "logout", required = false) String logout) {
ModelAndView model = new ModelAndView();
if (error != null) {
model.addObject("error", "Invalid username and password");
}
model.addObject("msg", "This is a message and stuff");
return model;
}
@RequestMapping(value = { "/welcome/{userName}", "/welcome" }, method = …Run Code Online (Sandbox Code Playgroud)