首页 > 解决方案 > 如何通过 Spring-boot 为特定登录用户应用 HTML 中的操作

问题描述

我面临一个问题,当我在登录的特定用户中执行操作并将其应用于所有其他用户时。执行的操作是单击在特定时间禁用的按钮。但是当我们切换登录用户时,更改也会出现在该用户中。

这是HTML代码

<button id="upside" type="submit" class="btn btn-success">Up</button>
<button id="downside" onclick="down()" type="submit" class="btn btn-danger">Down</button>

这是spring/java代码

@RequestMapping(value = "/add", method ={RequestMethod.POST, RequestMethod.GET})
public ModelAndView GoesUp(@AuthenticationPrincipal CustomUserDetails currentuser) throws IOException {
    if (isAuthenticated()) {       //isAuthenticated is function which check whether the user is logedin or not
    int x=currentuser.getBalance() +10;   //Balance is points available for that user to which we add 10
    currentuser.setBalance(x);
    repo.setUserInfoById(x,currentuser.getId()); // repo is a repository which modify changes in  database1
    repoofdata.setDataInfoById(x,currentuser.getId()); // repoofdata is a repository which modify changes in  database2
    return new ModelAndView("redirect:"+"/app1"); 
     }
    return new ModelAndView("redirect:"+"/signin"); // ( /signin ) is signing page.
}

这是 isAuthenticated() 函数 -

private boolean isAuthenticated() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication == null || AnonymousAuthenticationToken.class.
      isAssignableFrom(authentication.getClass())) {
        return false;
    }
    return authentication.isAuthenticated();
}

标签: javahtmlspring-boot

解决方案


推荐阅读