在这里一筹莫展,你考虑过 iBatis 吗?这是一个真正脚踏实地的查询映射框架(我不愿以某种方式称其为 ORM 框架)。您必须像这样创建 XML 文件:
<mapper namespace="org.mybatis.jpetstore.persistence.ProductMapper">
<cache />
<select id="getProduct" parameterType="string" resultType="Product">
SELECT
PRODUCTID,
NAME,
DESCN as description,
CATEGORY as categoryId
FROM PRODUCT
WHERE PRODUCTID = #{productId}
</select>
</mapper>
它连接了一个像这样的映射器:
public interface ProductMapper {
Product getProduct(String productId);
}
它允许您从以下服务访问数据:
@Autowired
private ProductMapper productMapper;
public Product getProduct(String productId) {
return productMapper.getProduct(productId);
}
您可以使用 Spring 连接:
<!-- enable autowire -->
<context:annotation-config />
<!-- enable transaction demarcation with annotations -->
<tx:annotation-driven />
<!-- define the SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="org.mybatis.jpetstore.domain" />
</bean>
<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="org.mybatis.jpetstore.persistence" />
</bean>
另请参阅完整的 petstore 示例。
我不是 iBatis 的明确粉丝,但它可能适合您在这种特定情况下的需求。