我正在开发一个Spring 3.1 MVC应用程序,对于我的一个场景,我不得不编写两个DAO实现.我想知道如何基于另一个对象的属性在服务层中自动装配它.
例如,
class Vehicle {
private name;
private type;
..
..
..
}
@Service
class VehicleServiceImpl implements VehicleService {
// There are two implementations to this DAO
// if Vehicle.type == "CAR", inject CarDAO
// if Vehicle.type == "TRAIN", inject TrainDAO
@Autowired
private VehicleDAO vehicleDAO ;
}
@Repository
class CarDAO implements VehicleDAO {
}
@Repository
class TrainDAO implements VehicleDAO {
}
Run Code Online (Sandbox Code Playgroud)
如果我的车辆是汽车,我需要自动装载CarDAO,如果是火车,我需要自动装载TrainDAO
在3.1版本中实现这一点的最佳方法是什么?
我希望使用上下文属性占位符或@Qualifier注释,但这些都是基于某些属性限制查找.我不知道如何在运行时基于另一个对象的属性执行此操作.
我试图在Spring MVC应用程序中使用NamedParameterJdbTemplate.问题是当我包含下面列出的ORDER BY子句之一时,绑定参数似乎不起作用(不进行排序).但是,sql中的列名称的硬编码顺序有效.
ORDER BY column1
ORDER BY column1
ORDER BY column1 asc
ORDER BY column1 desc
Run Code Online (Sandbox Code Playgroud)
例如,下面列出的查询不起作用.
private static final String SEARCH_ALL_BY_SORT_ORDER=
" select FIRST_NM, MIDDLE_NM, LAST_NM, CUSTOMER_IDENTIFIER, EMAIL_ADDRESS, ACCOUNT_ID" +
" from VIEW " +
" where CUSTOMER_IDENTIFIER= :customerIdentifier " +
" and ( REGEXP_LIKE(FIRST_NM, :firstName, 'i') " +
" or REGEXP_LIKE(LAST_NM, :lastName, 'i') " +
" or REGEXP_LIKE(EMAIL_ADDRESS, :emailAddress, 'i') )" +
" order by :sortColumns";
Run Code Online (Sandbox Code Playgroud)
按列的硬编码顺序的相同查询有效:
private static final String SEARCH_ALL_BY_SORT_ORDER=
" select FIRST_NM, MIDDLE_NM, LAST_NM, …Run Code Online (Sandbox Code Playgroud)