SpringBoot中mybatis多参数传递

使用Map封装

mybatis

<update id="testModify">
        update testTable
        <trim prefix="set (" suffix=")" sufiixOverrides=",">
                <if test="name != null">name = #{name},</if>
        </trim>
        where id = #{id}
</update>

Mapper层

@Mapper
@Repository
public interface TestTableMapper {
        void testModify(Map map);
}

Service层

public interface TestService {
        void modifyName(String name,  int id);
}

@Service
public class TestServiceImpl {
        @Autowired
        TestTableMapper testTableMapper;

        @Override
        public void modifyName(String name,  int id) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("name", name);
                map.put("id", id + "");
                testTableMapper.testModify(map);
        }
}
posted @ 2021-12-31 11:04  super970216  阅读(174)  评论(0)    收藏  举报