废话不多说,直接上代码
@UpdateProvider(type = AppProvider.class, method = "updateApp") Integer updateApp(@Param("appModel") AppModel appModel);
type:生成sql语句的类,method:类中对应的方法。
public class AppProvider extends SQL { private static final String TABLE_NAME = "t_application"; public String updateApp(@Param("appModel") AppModel appModel) { return new SQL(){{ UPDATE(TABLE_NAME); if (!StringUtils.isEmpty(appModel.getName())) { SET("name = #{appModel.name,javaType=String,jdbcType=VARCHAR}"); } if (!StringUtils.isEmpty(appModel.getPic())) { SET("pic= #{appModel.pic,javaType=String,jdbcType=VARCHAR}"); } if (!ObjectUtils.isEmpty(appModel.getIntroduce())) { SET("type= #{appModel.type,javaType=Long,jdbcType=BIGINT}"); SET("type_name= #{appModel.typeName,javaType=String,jdbcType=VARCHAR}"); } if (!StringUtils.isEmpty(appModel.getIntroduce())) { SET("introduce= #{appModel.introduce,javaType=String,jdbcType=VARCHAR}"); } WHERE("id = #{appModel.id,javaType=Long,jdbcType=BIGINT}" ); }}.toString(); } }
UPDATE(TABLE_NAME):要更新的表名;
update table_name;
SET("name = #{appModel.name,javaType=String,jdbcType=VARCHAR}");
appModel.name:appModel类name字段的值;
javaType=String:java语言中的数据类型;
jdbcType=VARCHAR:数据库对应的数据类型;
"set name = appModel_name"
WHERE("id = #{appModel.id,javaType=Long,jdbcType=BIGINT}" );
"where id = appModel_id";
————————————————
版权声明:本文为CSDN博主「Solyutian」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Solyutian/article/details/82593272