Mybatis系列之实战篇(下)实战总结将Mybatis和Spring配置文件独立开<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource" /><!– 自动扫描mapping.xml文件 –><property name="mapperLocations" value="classpath:com/emerson/etao/mapping/**/*.xml"></property><property name="configLocation" value="classpath:mybatis-config.xml"></property></bean><select id="getById" parameterType="int" resultType=""></select><select id="getAll" resultType=""></select><insert id="insert" parameterType="" useGeneratedKeys="true" keyProperty=""></insert><update id="update" parameterType=""></update><delete id="delete" parameterType="int"></delete>在映射文件的select元素中,不要使用select *,尽可能将每个字段写出来,如果有些字段会出现在多个select元素中,可以将其提取出来<sql id="selectColumns"></sql><sql id="insertColumns"></sql><select id="getById" parameterType="int" resultType="">SELECT<include refid="selectColumns"></include>FROM TABLENAME WHERE KEY_FIELD = #{id}</select>
以上是个人拙见,供参考。
版权声明:本文为博主原创文章,转载请注明出处。
,在时光的激流中,我们总会长大。