我正在使用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) 我有一个 Keycloak 用例,其中单个用户可能有多个客户号码。这些客户号码需要发送给服务提供商/客户,并且管理员也可以轻松更新。一些用户可能有数百个客户号码。目前我正在使用名为“customerNumbers”的单个用户属性,其中客户编号用逗号分隔,但我想:
我想要这样的东西:
而不是这个
"customers": {
"customerNumbers": "140661,140662"
},
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西:
"customers": [
{"customerNumber": "140661"},
{"customerNumber": "140662"}
],
Run Code Online (Sandbox Code Playgroud)
面对这种情况,应该如何应对呢?
我的应用程序中包含以下代码:
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甚至有可能?