小编Juk*_*nen的帖子

没有@Transactional注释的Spring托管事务

我正在使用Spring注释来管理我的交易,如下所示:

@Transactional(readOnly = true)
public class AlertServiceImpl implements AlertService {

     private AlertDAO alertDAO;

     public List<Alert> getAlerts(){
         List<Alert> alerts = alertDAO.getAlerts();
         return alerts;
     }

}
Run Code Online (Sandbox Code Playgroud)

我想知道如果忘记注释会发生什么:

// Oops! Forgot to use transactional annotation 
public class AlertServiceImpl implements AlertService {

    private AlertDAO alertDAO;

    public List<Alert> getAlerts(){
         List<Alert> alerts = alertDAO.getAlerts();
         return alerts;
    }

}
Run Code Online (Sandbox Code Playgroud)

当alertDAO实现如下:

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

// no annotation here either
public class HibernateAlertDAO extends HibernateDaoSupport implements AlertDAO {

    public List<Alert> getAlerts(){
         // some implementation details that define queryString

         Query query …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate transactions

18
推荐指数
1
解决办法
1万
查看次数

具有多个值的 Keycloak 用户属性(列表)

我有一个 Keycloak 用例,其中单个用户可能有多个客户号码。这些客户号码需要发送给服务提供商/客户,并且管理员也可以轻松更新。一些用户可能有数百个客户号码。目前我正在使用名为“customerNumbers”的单个用户属性,其中客户编号用逗号分隔,但我想:

  1. 为管理员提供在其自己的字段中查看每个客户编号的可能性
  2. 将客户编号作为 JSON 数组而不是逗号分隔的声明发送

所以代替这个: 在此输入图像描述

我想要这样的东西:

在此输入图像描述

而不是这个

"customers": {
"customerNumbers": "140661,140662"
},
Run Code Online (Sandbox Code Playgroud)

我想要这样的东西:

"customers": [
    {"customerNumber": "140661"},
    {"customerNumber": "140662"}
],
Run Code Online (Sandbox Code Playgroud)

面对这种情况,应该如何应对呢?

customization keycloak

9
推荐指数
2
解决办法
9403
查看次数

如何避免Java反射中的魔术字符串

我的应用程序中包含以下代码:

for(PropertyDescriptor property : myObjectProperties){
    if(property.getName().equals("myPropertyName")){
         // logic goes here
    }
}
Run Code Online (Sandbox Code Playgroud)

这当然在多个级别上都是危险的,可能最糟糕的是,如果我在“ MyObject”上重命名属性“ myPropertyName”,则代码将中断。

也就是说,在不显式键入属性的情况下引用属性名称的最简单方法是什么(因为这将使我得到编译器警告)?我看起来像:

for(PropertyDescriptor property : myObjectProperties){
    if(property.getName().equals(MyObject.myPropertyName.getPropertyName())){
         // logic goes here
    }
}
Run Code Online (Sandbox Code Playgroud)

还是Java甚至有可能?

java reflection

5
推荐指数
1
解决办法
914
查看次数