java - 如何通过 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();
}
解决方案
推荐阅读
- mongodb - Groupby 数组元素并根据 Mongodb 查询中的日期对其进行分类
- javascript - 为什么我们使用 this.initialState = this.state;
- c++ - GCC / G++ 路径包含标志以 '=' 开头
- python - 为什么我的海龟绘图程序在 2 个动作后就死了
- fgets - 从 gcc 中的“fgets”中删除换行符
- angular - 角度 texarea 到阵列管道
- c++ - 试图从一个带有参数函数的函数返回一个函数
- css - 将特定的 woocommerce 子类别显示为没有空格的列表
- python - Pandas 合并:df1.merge(df2, on='Date') 不合并,左侧数据框 df1 保持不变?
- php - 此路由不支持 POST 方法。支持的方法:GET、HEAD。我想将数据从 curl 保存到数据库表