字典映射表字段
框架:spring+mybatis
mapper.xml文件中resultType=table对象,结果集结构为驼峰类型,与要求不符,舍弃;resultType=java.util.Map,结果集为map对像,结果符合,但是结果为null会自动舍弃数据,不符合要求,舍弃
解决方案:
mapper.xml 自定义结果集结构
hu
create table test(
test_aa varchar(32),
test_bb varchar(32),
test_cc varchar(32)
)
public class test{
private String testAa;
private String testBb;
private String testCc;
}
mapper.xml
<select id="testSql" resultMap="testData" parameterType="java.lang.String">
${sql}
</select>
<resultMap id="testData" type="com.demp.entity.test">
<id column="testAa" property="test_aa"></id>
<id column="testBb" property="test_bb"></id>
<id column="testCc" property="test_cc"></id>
</resultMap>
String sql="select test_aa as testAa,test_bb as testBb,test_cc as testCc from test"
test info = mapper.testData(sql);
Class<? extends test> clazz = info.getClass();
Field[] fields = clazz.getDeclaredFields();
for(Field field:fields){
field.setAccessible(true);
String fieldName = field.getName();
Object value = field.get(info);
...
}