mybatis注解

使用注解
public interface ActivityDao {

    final static String INSERT = "insert into activity (ALIPAY_ID, REAL_NAME,PHONE_NUMBER, WANGWANG_ID, ACTIVITY_INFO, ACTIVITY_NAME, STATUS, GMT_CREATE, GMT_MODIFY) values (#{alipayId,jdbcType=VARCHAR}, #{realName,jdbcType=VARCHAR}, #{phoneNumber,jdbcType=BIGINT}, #{wangwangId,jdbcType=VARCHAR}, #{activityInfo,jdbcType=VARCHAR}, #{activityName,jdbcType=VARCHAR},#{status,jdbcType=TINYINT},#{gmtCreate,jdbcType=DATE},#{gmtModify,jdbcType=DATE})";

    final static String SELECT = "select * from activity where id = #{id}";

    @Insert(INSERT)
    public void insert(Activity record);

    @UpdateProvider(type = ActivityProvider.class, method = "update")
    public void update(Activity activity);

    @Select(SELECT)
    @Results(value = {
            @Result(id = true, column = "ID", property = "id", jdbcType = JdbcType.BIGINT),
            @Result(column = "ALIPAY_ID", property = "alipayId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "REAL_NAME", property = "realName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "PHONE_NUMBER", property = "phoneNumber", jdbcType = JdbcType.BIGINT),
            @Result(column = "WANGWANG_ID", property = "wangwangId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "ACTIVITY_INFO", property = "activityInfo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "ACTIVITY_NAME", property = "activityName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "STATUS", property = "status", jdbcType = JdbcType.TINYINT),
            @Result(column = "GMT_CREATE", property = "gmtCreate", jdbcType = JdbcType.DATE),
            @Result(column = "GMT_MODIFY", property = "gmtModify", jdbcType = JdbcType.DATE) })
    public Activity selectById(Integer id);
}

public class ActivityProvider {
    private static final String UPDATE_SQL_PRE = "update activity ";

    public static String update(Activity activity) {
        StringBuilder builder = new StringBuilder();
        builder.append(UPDATE_SQL_PRE + "set ");
        if (activity.getAlipayId() != null)
            builder.append("ALIPAY_ID = '" + activity.getAlipayId() + "'");

        if (activity.getRealName() != null)
            builder.append(",REAL_NAME = '" + activity.getRealName() + "'");

        if (activity.getPhoneNumber() != null)
            builder.append(",PHONE_NUMBER = '" + activity.getPhoneNumber() + "'");

        if (activity.getWangwangId() != null)
            builder.append(",WANGWANG_ID = '" + activity.getWangwangId() + "'");

        if (activity.getActivityInfo() != null)
            builder.append(",ACTIVITY_INFO = '" + activity.getActivityInfo() + "'");

        if (activity.getActivityName() != null)
            builder.append(",ACTIVITY_NAME = '" + activity.getActivityName() + "'");

        builder.append(" where id = " + activity.getId());

        return builder.toString();
    }
}

你可能感兴趣的:(注解,mybatis)