Postgresql результат не соответствует базе данных с использованием mybatis - PullRequest
0 голосов
/ 26 марта 2020

config. xml

<mapper namespace="com.###.mapper.EmployeeMapper" >
    <resultMap id="EmployeeMap" type="com.###.model.Employee">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="type" property="type"/>
        <result column="authority" property="authority"/>
        <result column="tel" property="tel"/>
        <result column="extra" property="extra"/>
    </resultMap>

    <select id="getById" parameterType="java.lang.String"  resultMap="EmployeeMap" >
        SELECT  * from employee WHERE  id=#{id}
    </select>
</mapper>

тестовый код

@Test
void insert() {
    // 插入新行
    Employee employee = new Employee("", "张三", "教授", null, "13122107768", null);
    employeeMapper.insert(employee);
    // 查询新行
    Assert.assertEquals(employee,employeeMapper.getById(employee.getId()));
}

результат

Ожидаемый: Employee(id=28, name=张三, type=教授, authority=null, tel=13122107768, extra=null)

Факт: Employee(id=28, name=张三, type=教授, authority=13122107768, tel=13122107768, extra=张三)

database view

1 Ответ

0 голосов
/ 26 марта 2020

Я понял! Класс сущности должен иметь конструктор без аргументов

...