If the SQL column name is Snake case and the mapping destination java is Camel case, Settings that automatically convert from camel to snake with mybatis.
I use this.
application.yml
mybatis:
configuration:
map-underscore-to-camel-case: true
application.properties
mybatis.configuration.map-underscore-to-camel-case=true
application.yml
mybatis:
config-location: classpath:/mybatis/mybatis-config.xml
mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="true" />
</settings>
</configuration>
Todo.java
class Todo {
private Integer id;
private String statusNm; //Status in this field_I want to enter the value of nm
}
TodoListMapper.java
@Mapper
public interface TodoListMapper {
/**
*Search the list.
* @return TODO list
*/
List<Todo> selectList();
}
TodoListMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hellospring.mapper.TodoListMapper">
<select id="selectList" resultType="com.hellospring.domain.Todo">
SELECT
id
,status_nm
FROM
todo
</select>
</mapper>
Recommended Posts