每日记载内容总结45

  1. 基本的xml配置

     the basic structure of XML-based configuration metadata:
     <?xml version="1.0" encoding="UTF-8"?>
     <beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans.xsd">
     
         <bean id="..." class="...">
             <!-- collaborators and configuration for this bean go here -->
         </bean>
     
         <bean id="..." class="...">
             <!-- collaborators and configuration for this bean go here -->
         </bean>
     
         <!-- more bean definitions go here -->
     </beans>
    

    beans —— xml文件的根节点。

    xmlns ——是XML NameSpace的缩写,因为XML文件的标签名称都是自定义的,自己写的和其他人定义的标签很有可能会重复命名,而功能却不一样,所以需要加上一个namespace来区分这个xml文件和其他的xml文件,类似于java中的package。

    xmlns:xsi ——是指xml文件遵守xml规范,xsi全名:xml schema instance,是指具体用到的schema资源文件里定义的元素所准守的规范。即/spring-beans-2.0.xsd这个文件里定义的元素遵守什么标准。

    xsi:schemaLocation——是指,本文档里的xml元素所遵守的规范,schemaLocation 属性用来引用(schema)模式文档,解析器可以在需要的情况下使用这个文档对 XML 实例文档进行校验。它的值(URI)是成对出现的,第一个值表示命名空间,第二个值则表示描述该命名空间的模式文档的具体位置,两个值之间以空格分隔。

  2. Mybatis if test 判断数字时需要注意
    mybatis做if 判断 注意:下面这种写法只适用于 id 类型为字符串.

       <if test="id != null and id != '' ">
           id = #{id}
       </if>
    

    如果id类型为int 当id=0时 这个判断不会进入.可以这样写

     <if test="id != null and id != '' or id==0">
    
  3. Mybatis where set关于多余的符号或者连接符的处理

     WHERE:
     <where>
     	<if test="phone != null and phone != ''">
     		`CONTACT_PHONE`=#{phone}
     	</if>
     	<if test="shopperName != null and shopperName != ''">
     		AND `SHOPKEEPER_NAME`=#{shopperName}
     	</if>
     	<if test="status != null and status != ''">
     		AND `STATUS`=#{status}
     	</if>
     	<if test="startTime != null and startTime != ''">
     		AND `CREATE_TIME`<![CDATA[ >= ]]> #{startTime}
     	</if>
     	<if test="endTime != null and endTime != ''">
     		AND `CREATE_TIME` <![CDATA[ <= ]]> #{endTime}
     	</if>
     </where>
     
     SET:
     <set> 
     	<if test="name != null">
     	 `NAME` = #{name},
     	 </if>
     	 <if test="describe != null">
     	 `DESCRIBE` = #{describe},
     	 </if>
     	 <if test="headImg != null">
     	 `HEAD_IMG` = #{headImg}
     	 </if>
      </set>
    
  4. Mybatis 循环拼凑参数

     <foreach collection="stateTypeArr" index="index" item="item" open="b.STATE_TYPE IN(" separator="," close=")">
         #{item}
     </foreach>
    
  5. 拼凑表名,必须用${}

     SELECT * FROM `SSQS_ORDER_PRODUCT_${param2}` WHERE `ORDER_ID`=#{param1}
    
  6. springMVC下载文件(简单粗暴)

     controller
     @RequestMapping(name="下载提现记录",path ="/download", method = RequestMethod.GET, consumes = "application/octet-stream;charset=utf-8")
    
     String fileName = "WITHDRAW_RECORDS";
     response.setHeader("Content-Disposition", "attachment;filename='" + fileName + ".csv'");
     StringBuilder sBuilder = new StringBuilder();
     sBuilder.append("序号,用户ID,提现金额,可提现金额,银行,卡号,用户名,手机号,身份证号,提现时间,状态,备注");
     StringUtils.appendLine(sBuilder);
     for (int i = 0; i < withdraws.size(); i++) {
     	ResUserWalletWithdraw resUserWalletWithdraw = withdraws.get(i);
     	if (resUserWalletWithdraw != null){
     		sBuilder.append(resUserWalletWithdraw.exportToCsv());
     		StringUtils.appendLine(sBuilder);
     	}
     }
     return sBuilder.toString();
    
     entity
     public String exportToCsv(){
     	String statusStr = StringUtils.isNotBlank(status) ? 
     			(StringUtils.equals(status, "PENDING") ? "等待打款": 
     				(StringUtils.equals(status, "COMPLETED") ? "打款成功" : "打款失败")):"";
     	return new StringBuilder()
     			.append(id).append(",")
     			.append(storeId).append(",")
     			.append(new BigDecimal(amount).divide(new BigDecimal("100")).setScale(0, BigDecimal.ROUND_HALF_UP).toString()).append(",")
     			.append(new BigDecimal(amountTotal).divide(new BigDecimal("100")).setScale(0, BigDecimal.ROUND_HALF_UP).toString()).append(",")
     			.append(bank).append(",")
     			.append(card).append(",")
     			.append(realName).append(",")
     			.append(phone).append(",")
     			.append(StringUtils.isBlank(certificateCode)?"":certificateCode).append(",")
     			.append(DateUtils.format(time)).append(",")
     			.append(statusStr).append(",")
     			.append(StringUtils.isBlank(reason)?"":reason)
     			.toString();
     }
    

    页面直接用a标签拼凑链接和参数即可。
    注:filename = '*.csv' 需要加引号,不然chrome不兼容。

posted @ 2017-08-04 18:13  CalronLoveRonnie  阅读(185)  评论(0编辑  收藏  举报
AmazingCounters.com