8 - 动态SQL--set

set if
dao

int updateStudent(Student student);

mapper

 
        update `student`
        
            
                `name` = #{name},
            
            
                `age` = #{age},
            
            
                `gender` = #{gender,typeHandler=genderTypeHandler}
            
        
        where `id` = #{id}
    

test


    @Test
    public void test() {
        SqlSession session = factory.openSession();
        try {
            StudentMapper studentMapper = session.getMapper(StudentMapper.class);
            int id = 10001;
            String name = "hu";
            int age = 18;
            GenderEnum gender = GenderEnum.getGender(1);
            Student student = new Student(id,name,age,gender);
            int affectedRows = studentMapper.updateStudent(student);
            System.out.println(affectedRows);
            System.out.println(studentMapper.selectStudentById(id));
        } finally {
            session.commit();
            session.close();
        }
    }

你可能感兴趣的:(8 - 动态SQL--set)