यहाँ एक अंग पर बाहर जाने को देखने मिलेगा? यह पृथ्वी क्वेरी मैपिंग ढांचे के लिए एक वास्तविक नीचे है (मैं इसे किसी भी तरह से एक ओआरएम ढांचे को कॉल करने में संकोच करता हूं)। आप इस तरह एक्सएमएल फाइल बनाने के लिए:
<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);
}
जो आप वसंत के साथ तार कर सकते हैं:
<!-- 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>
the full petstore example भी देखें।
मैं iBatis का एक विशिष्ट प्रशंसक नहीं हूं लेकिन यह इस विशिष्ट मामले में आपकी आवश्यकताओं को पूरा कर सकता है।
स्रोत
2011-08-09 08:36:52
यदि आप पहले से ही जानते हैं कि समान प्रश्न हैं, तो यह * महान * है कि आप हमें उनके बारे में बताते हैं। लेकिन हमें बता रहा है ** क्यों ** ये प्रश्न आप जो चाहते हैं वह बेहतर नहीं होगा! –
इसे लिखने में आपकी समस्या क्या है? –
हाइबरनेट के साथ समस्या क्या है, इसकी महान ... – NimChimpsky