【发布时间】:2016-12-13 00:29:32
【问题描述】:
我目前正在处理由第三方承包商构建的遗留项目。它是一个使用 Spring 和 MyBatis 并与 MySQL 服务器对话的 Java 服务器。
我试图在我的 DTO getter/setter 中重构一些丑陋的方法名称,其中包含 CamelCase 和下划线。我将使用方法getCommon_name() 作为示例。当我将其重命名为 getCommonName()) 时,该方法的数据库查找停止工作。我尝试进行文本搜索以查找调用该方法的代码中出现的情况,但它似乎只存在于 DTO 定义中。可能有一些我无法正确理解的到数据库的自动映射,因为该方法会查找一个名为 common_name 的表,但我不能确定。
有没有人能够对可能发生的事情有所了解?这是我第一次使用 Spring/MyBatis。
编辑更多细节:
到目前为止,答案一直在询问我的映射是如何设置的。它看起来像这样:
mybatis-config.xml
<configuration>
<typeAliases>
<typeAlias type="com.example.dto.SpeciesDTO" alias="species" />
<!--aliases for other DTOs-->
</typeAliases>
<mappers>
<mapper resource="com/example/dao/species/speciesSQL.xml" />
<!--aliases for other DAOs-->
</mappers>
</configuration>
mybatis-context.xml
<beans>
<bean id="SpeciesDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface"
value="com.example.dao.species.SpeciesDAO" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
<!--beans for other DAOs-->
</beans>
此外,DAO 文件都有相关联的 .xml 文件,如下所示:
<mapper namespace="com.example.species.speciesDAO">
<select id="getSpecies" parameterType="String" resultType="species">
SELECT * FROM SPECIES
</select>
<!--other methods executing SQL-->
</mapper>
我还没有看到任何以 DAO 方法的方式显式映射 DTO getter/setter 的东西。例如,如果我搜索方法 getCommon_name(),唯一出现的是 DTO 本身中的定义以及在我的一个服务中对该方法的调用(我确保在重命名该方法时编辑了这两个事件)。该方法所做的只是返回一个名为common_name 的属性。
【问题讨论】:
-
如果不查看您的 DTO 和注释/映射文件,很难判断。就像你说的,可以根据你的字段名称自动映射。
-
问题是,一个完整的项目文本搜索应该返回到我修改的方法的映射(如果它们存在的话)。似乎映射发生在我的代码之外的某个地方。