zoukankan      html  css  js  c++  java
  • 代码优雅

    1. 功能复用,写成公共方法。

    2.mybatis 不应该用 select * 

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
    <mapper namespace="com.hengxin.qianee.mapper.DictBankingMapper" >
      <resultMap id="BaseResultMap" type="com.hengxin.qianee.model.DictBanking" >
        <id column="id" property="id" jdbcType="INTEGER" />
        <result column="name" property="name" jdbcType="VARCHAR" />
        <result column="bank_code" property="bankCode" jdbcType="VARCHAR" />
        <result column="amount_day_limit" property="amount_day_limit" jdbcType="DECIMAL" />
        <result column="amount_single_limit" property="amount_single_limit" jdbcType="DECIMAL" />
        <result column="amount_month_limit" property="amount_month_limit" jdbcType="DECIMAL" />
        <result column="is_use" property="is_use" jdbcType="INTEGER" />
        <result column="images_path" property="images_path" jdbcType="VARCHAR" />
        <result column="images_path_wx" property="imagesPathWx" jdbcType="VARCHAR" />
        <result column="images_path_wx" property="imagesPathWx" jdbcType="VARCHAR" />
      </resultMap>
      <sql id="Base_Column_List" >
        id, name, images_path,amount_single_limit,amount_day_limit,amount_month_limit,is_use,images_path_wx
      </sql>
      <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
        select 
        <include refid="Base_Column_List" />
        from t_dict_banking
        where id = #{id,jdbcType=INTEGER}
      </select>
      
      <!-- 查询所有银行信息/图标、图片地址 -->
      <select id="selectBankingAll" resultMap="BaseResultMap">
        select 
        <include refid="Base_Column_List" />
        from t_dict_banking
      </select>
      
      <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
        delete from t_dict_banking
        where id = #{id,jdbcType=INTEGER}
      </delete>
      
      <!-- 增加银行 -->
      <insert id="insert" parameterType="com.hengxin.qianee.model.DictBanking" >
        insert into t_dict_banking (id, name, images_path,amount_day_limit,amount_single_limit,amount_month_limit,is_use
          )
        values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{images_path,jdbcType=VARCHAR},#{amount_day_limit,jdbcType=DECIMAL},
                #{amount_single_limit,jdbcType=DECIMAL},#{amount_month_limit,jdbcType=DECIMAL},#{is_use,jdbcType=INTEGER}
          )
      </insert>
      
      <insert id="insertSelective" parameterType="com.hengxin.qianee.model.DictBanking" >
        insert into t_dict_banking
        <trim prefix="(" suffix=")" suffixOverrides="," >
          <if test="id != null" >
            id,
          </if>
          <if test="name != null" >
            name,
          </if>
          <if test="images_path != null" >
            images_path,
          </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
          <if test="id != null" >
            #{id,jdbcType=INTEGER},
          </if>
          <if test="name != null" >
            #{name,jdbcType=VARCHAR},
          </if>
          <if test="images_path != null" >
            #{images_path,jdbcType=VARCHAR},
          </if>
        </trim>
      </insert>
      <update id="updateByPrimaryKeySelective" parameterType="com.hengxin.qianee.model.DictBanking" >
        update t_dict_banking
        <set >
          <if test="name != null" >
            name = #{name,jdbcType=VARCHAR},
          </if>
          <if test="images_path != null" >
            images_path = #{images_path,jdbcType=VARCHAR},
          </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
      </update>
      
      <!-- 保存修改银行卡信息 -->
      <update id="updateByPrimaryKey" parameterType="com.hengxin.qianee.model.DictBanking" >
        update t_dict_banking
        set name = #{name,jdbcType=VARCHAR},
        images_path = #{images_path,jdbcType=VARCHAR},
        amount_day_limit = #{amount_day_limit,jdbcType=DECIMAL},
        amount_single_limit = #{amount_single_limit,jdbcType=DECIMAL},
        amount_month_limit = #{amount_month_limit,jdbcType=DECIMAL},
        is_use = #{is_use,jdbcType=INTEGER}
        where id = #{id,jdbcType=INTEGER}
      </update>
      <!-- 微信用:根据银行编码获得银行信息 -->
      <select id="selectByBankCode" resultMap="BaseResultMap" parameterType="string" >
        select 
        <include refid="Base_Column_List" />
        from t_dict_banking
        where bank_code = #{bankCode} and type = 2 and is_use = 1
      </select>
    </mapper>

    3.不确定 查询语句是否能返回对象 而是有可能返回null时,要先判断该对象是否为null,再去取对象中的值。

    4.金额等 double(Double)值相减的时候会丢失精度,转成“字符串”再转成BigDecimal

      BigDecimal amountBG = new BigDecimal(amount.toString());

      BigDecimal hasInvestedAmountBG = new BigDecimal(hasInvestedAmount.toString());

      double money = amountBG.subtract(hasInvestedAmountBG).doubleValue();

  • 相关阅读:
    对offsetHeight,clientHeight,scrollHeight的理解
    对word-wrap和word-break的理解
    数据结构之线性表(严蔚敏《数据结构》要求)
    1-数据结构之线性表
    结构体变量声明及初始化的的那些坑
    指针与函数
    数组的深入理解
    0-绪论
    别让无知成恶趣!
    电路分析-3
  • 原文地址:https://www.cnblogs.com/weixiaole/p/5340895.html
Copyright © 2011-2022 走看看