Mybatis动态表字段更新,主要通过$符号完成,如下示例:
@Data
public class FileVo {
/**
* id
*/
private Long id;
/**
* 文件id
*/
private String fileId;
}
@Mapper
@Repository
public interface FileMapper {
int updateBizTable(FileVo fileVo);
FileVo selectVoFromBizTableById(FileVo fileVo);
}
<update id="updateBizTable">
update ${tableName}
set ${columnName} = #{fileId}
where id = #{id}
</update>
<select id="selectVoFromBizTableById" resultType="FileVo">
select
id,
${columnName} as test,
"${columnName}" as columnName,
"${tableName}" as tableName
from ${tableName}
where id = #{id}
</select>