自己写过的一些比较常用的代码,mybatis

1.mybatis传List查询的情况
<select id="selectProLedgerList" resultType="com.ssic.educateion.common.dto.ProLedgerDto"
        parameterType="java.util.List">
        SELECT a.wares_id AS waresId,b.ware_batch_no AS batchNo, b.start_address AS startAddress ,b.action_date as actionDate
        FROM t_pro_ledger a
        LEFT JOIN t_pro_ledger_master b ON a.master_id = b.id
        WHERE a.stat = 1 AND b.stat = 1
        <if test="waresIdList != null">
            and a.wares_id  in
         <foreach collection="waresIdList" item="id" index="index"
                open="(" close=")" separator=",">
                #{id}
         </foreach>
        </if>
        ORDER BY a.`create_time` DESC
</select>
   mybatis传List插入的情况
<insert id="addNutritionalBatch" parameterType="java.util.List">  
  INSERT INTO t_pro_nutritional (id, package_id,name,unit,weight, create_time, stat)
  VALUES
    <foreach collection="list" item="item" index="index" separator="," >  
        (#{item.id},#{item.packageId},#{item.name},#{item.unit},#{item.weight},#{item.createTime},#{item.stat})  
    </foreach>
</insert>  

2.Js格式化日期方法
Date.prototype.format = function (pattern) {
var format = pattern || "yyyy-MM-dd HH:mm:ss";
var o = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"H+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"S": this.getMilliseconds(),
"q+": Math.floor((this.getMonth() + 3) / 3) //季度
};
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1
? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
};

3.Mybatis根据  in   List  查询
<if test="ledgerDto.waresNameList != null">
         and a.name  in
         <foreach collection="ledgerDto.waresNameList" item="name" index="index"
                open="(" close=")" separator=",">
                #{name}
         </foreach>
</if>

4.freemarker中map集合的遍历:
<thead>
        <tr>
            <th width="100">来源方式</th>
            <th width="120">人数</th>
        </tr>
</thead>
<tbody>
    <#if clientSourceData?exists>
        <#list clientSourceData?keys as key>
           <tr>
                   <td>${key}</td>
                   <td>${clientSourceData.get(key)}</td>
           </tr>
        </#list>
    </#if>
    <tr>
           <td>合计:</td>
           <td>${totalNum}</td>
   </tr>
</tbody>
</table>

5.D:\git\education\education\education-government\src\main\webapp\WEB-INF\view\v2\notice\release_notice.htm:
<!DOCTYPE html>
<html ng-app="tempName">
<head>
  <meta charset="utf-8">
  <title>通知发布</title>
</head>
<body>
<div class="header">
    <#include "/v2/common/header.htm" />
    <link rel="stylesheet" href="/static/v2/css/pub.css">
    <link rel="stylesheet" href="/static/v2/ueditor/themes/iframe.css">
</div>

<div class="breadcrumb"></div>
<div class="heading">通知发布</div>

<div class="container pub">
  <div class="content_wrap">
    <form action="#" class="form_style ggpub-form" id="submitForm">
      <div class="row">
        <label for="lianxiList">联系人:</label>
        <input type="text" name="people" id="lianxiList" name="to">
        <a href="javascript:void(0)" class="btn-add">+</a>
      </div>

      <div class="row">
        <label for="title">标题:</label>
        <input type="text" name="title" id="title">
      </div>

      <div class="row">
        <label for="">内容:</label>
        <div id="" class="ggpub-content">
          <script id="editor" type="text/plain" style="width: 820px; height: 300px;"></script>
        </div>
      </div>

      <div class="row">
        <div class="btn_wrap">
          <span class="btn btn-active" id="savebutton">发布</span>
          <span class="btn">取消</span>
        </div>
      </div>
    </form>
  </div>

</div>

<div class="footer">
    <#include "/v2/common/footer.htm" />
</div>

<div class="pop_bg hide">
    <div class="pop_wrap">
        <h3 class="pop_title">添加联系人 <img src="/static/v2/imgs/pop_close.png" id="close"/></h3>
        <div class="search">
            <input type="text" id="searchV" name="search" value="">
            <img src="/static/v2/imgs/search_bt.png" id="searchName"/>
        </div>
        <ul class="select_list" >
            <li>
                <div class="color_checkbox">
                    <input type="checkbox" name="lianxiIdsss" id="all" onclick="checkboxClick(this);">
                    <label class="check_label_icon" for="all">
                        <img src="/static/v2/imgs/check_.png" />
                        <img class="active" src="/static/v2/imgs/check_active.png" />
                    </label>
                    <span>
                        全选
                    </span>
                </div>
            </li>
            <div id="dataList">
           <#if dataList ??>
                   <#list dataList as data>
                   <li>
                <div class="color_checkbox">
                    <input type="checkbox" name="lianxiIds" id="${(data.id)!}"  value="${(data.id)!}#${(data.name)!}" >
                        <label class="check_label_icon" for="${(data.id)!}">
                        <img src="/static/v2/imgs/check_.png" />
                        <img class="active" src="/static/v2/imgs/check_active.png" />
                    </label>
                    <span>${(data.name)!}</span>
                 </div>
                    </li>
                   </#list>
               </#if>
               </div>
           <!--  <li>
                <div class="color_checkbox">
                    <input type="checkbox" name="lianxiIdsss" id="abc" onclick="checkboxClick(this);">
                    <label class="check_label_icon" for="abc">
                        <img src="/static/v2/imgs/check_.png" />
                        <img class="active" src="/static/v2/imgs/check_active.png" />
                    </label>
                    <span>
                            上海程联餐饮公司
                    </span>
                </div>
            </li> -->
        </ul>
        <div class="bt_wrap">
            <span class="bt active">确认关联</span>
        </div>
    </div>
</div>

<!-- <script src="/js/angular.min.js"></script>
<script src="/js/jquery-1.12.3.min.js"></script>
<script charset="utf-8" src="ueditor/ueditor.config.js"></script>
<script charset="utf-8" src="ueditor/ueditor.all.min.js"> </script>
<script charset="utf-8" src="ueditor/lang/zh-cn/zh-cn.js"></script>
-->
<link href="/static/v2/umeditor1.2.2/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
<script type="text/javascript" charset="utf-8" src="/static/v2/umeditor1.2.2/umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/v2/umeditor1.2.2/umeditor.min.js"> </script>
<!--建议手动加在语言,避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型,比如你在配置项目里配置的是英文,这里加载的中文,那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="/static/v2/umeditor1.2.2/lang/zh-cn/zh-cn.js"></script>           
 
<link href="/static/v2/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
<!-- <script type="text/javascript" src="${base}/plugins/uploadify/jquery-1.3.2.min.js"></script> -->
<script type="text/javascript" src="/static/v2/uploadify/swfobject.js"></script>
<script type="text/javascript" src="/static/v2/uploadify/jquery.uploadify.v2.1.4.min.js"></script>      
   
<script>
  window.UMEDITOR_CONFIG.imagePath = "${(wwwdomain)!}";
<!--自定义toobar-->
  window.UMEDITOR_CONFIG.toolbar = [
        'source | undo redo | bold italic underline strikethrough | superscript subscript | forecolor backcolor | removeformat |',
        'insertorderedlist insertunorderedlist | selectall cleardoc paragraph | fontfamily fontsize' ,
        '| justifyleft justifycenter justifyright justifyjustify |',
        'link unlink | emotion image',
        '| horizontal print preview fullscreen', 'drafts', 'formula'
  ];        
</script>  

<!--  <script src="/js/app.js"></script> -->
<script>
/*    var ue = UE.getEditor('editor', {
     autoHeightEnabled: true,
     autoFloatEnabled: true,
     zIndex: 0
   }); */

   $(function(){
       /* $(".footer").css({
           "position":"relative"
       }) */

       $("a.btn-add").click(function(){
           $(".pop_bg").show();
       });

       $("#close").click(function(){
           $(".pop_bg").hide();
       });
       
       $(".bt_wrap").click(function(){
           $(".pop_bg").hide();
       });

       //复选框
       $(".select_list input[type='checkbox']").not("#all").click(function(){
           var check_num = $(this).closest(".select_list").find("input[type='checkbox']").length;

           if ($("#all").prop("checked","checked") && $(this).closest(".select_list").find("input[type='checkbox']:checked").length < check_num) {
               $("#all").prop("checked","");
           }

           if ($(this).closest(".select_list").find("input[type='checkbox']:checked").length == check_num-1  ){
               $(this).closest("li").siblings().find("input").prop("checked","checked");
           }
       });

       $("#all").click(function(){

            if ($(this).prop("checked")) {
                $(this).closest("li").siblings().find("input").prop("checked","checked");
            } else {
                $(this).closest("li").siblings().find("input").prop("checked","");
            }

       });
   });

</script>
<script>
            $(function(){
                  var um = UM.getEditor('editor');
                  
              $(".nav").find("a").removeClass("cur");
              $(".nav").find("a:eq(6)").addClass("cur");
                loadClickFunction();

                $("#searchName").on('click',function(){
                    var name = $("#searchV").val();
                    var ajaxParams = {name:name}
                    $.ajax({
                        url : "/motive/ajaxSearch.htm",
                        type:"POST",
                        data : ajaxParams,
                        dataType:'json',
                        success:function(data){
                            if(data.status==200){
                                var dataList = $("#dataList");
                                dataList.empty();
                                $.each(data.data, function(index, item) {
                                    //dataList.append("<li><label for='shisan'>"+item['name']+"</label><input name='lianxiIds' type='checkbox' value='"+item['id']+"#"+item['name']+"'/></li>");
                                    dataList.append("<li><div class=\"color_checkbox\"><input type=\"checkbox\" name=\"lianxiIds\" id='"+item['id']+"'  value='"+item['id']+"#"+item['name']+"'><label class=\"check_label_icon\" for='"+item['id']+"'><img src=\"/static/v2/imgs/check_.png\" /><img class=\"active\" src=\"/static/v2/imgs/check_active.png\" /></label><span>"+item['name']+"</span></div></li>");
                                });
                                $("#lianxiList").val("");
                                $("input[name='lianxiIdsss']").prop("checked",false);
                                loadClickFunction();
                            }else{
                                
                            }
                        }
                    });
                });
                
                $("#savebutton").on('click',function(){
                    var ajaxParams = $("#submitForm").serialize();
                    
                    var lianxiList = $("#lianxiList").val();
                    if(lianxiList=="" || lianxiList ==null){
                        //alert("联系人不能为空");
                        layer.msg("联系人不能为空");
                        return false;
                    };
                    
                    var title = $("#title").val();
                    if(title=="" || title ==null){
                        //alert("标题不能为空");
                        layer.msg("标题不能为空");
                        return false;
                    };
                    
                    var content = um.getContent();
                    if(content=="" || content ==null){
                        //alert("内容不能为空");
                        layer.msg("内容不能为空");
                        return false;
                    };                    
                    
                    $.ajax({
                        url : "/motive/save.htm",
                        type:"POST",
                        data : ajaxParams,
                        dataType:'json',
                        success:function(data){
                            if(data.status==200){
                                //alert("发布成功");
                                layer.msg("发布成功");
                                window.location.href = "/motive/noticeCenter.htm";
                            }else{
                                
                            }
                            
                        }
                    });
                });
                
                $("#plus_bt").click(function(){
                    $(".background").show();
                });

                $(".subbt").click(function(){
                    $(".background").hide();
                });
                
                $(".background .close").click(function(){
                    $(".background").hide();
                });

            });
            
            //全选点击事件
            function checkboxClick(objThis){
                //console.log($(objThis).prop("checked"));
                var lianxiList = "";
                if($(objThis).prop("checked")){
                    $("input[name='lianxiIds']").prop("checked",true);
                    $("input[name='lianxiIds']").each(function(index,item){
                        lianxiList += $(item).parent().find("span").html() + ","
                    });
                }else{
                    $("input[name='lianxiIds']").prop("checked",false);
                    lianxiList = "";
                }
                var lianxiLists;
                if(lianxiList.length > 0) {
                    lianxiLists=lianxiList.substring(0,lianxiList.length-1);
                }
                $("#lianxiList").val(lianxiList);
            }
            
            
            //多选框点击事件
            function loadClickFunction(){
                $("input[name='lianxiIds']").on('click',function(){
                    var lianxiList = "";
                    var lianxiIds = "";
                    $("input[name='lianxiIds']").each(function(){
                        if (true == $(this).prop("checked")) {
                            //console.log( $(this).parent().find("span").html());
                            lianxiList += $(this).parent().find("span").html() + ","
                            //lianxiIds  += $(this).val()+ ",";
                        }
                    });
                    var lianxiLists;
                    if(lianxiList.length > 0) {
                        lianxiLists=lianxiList.substring(0,lianxiList.length-1);
                    }
                    //console.log(lianxiList);
                    $("#lianxiList").val(lianxiList);
                    //$("#lianxiIds").val(lianxiIds);
                });                
            };
</script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/jam_yin/article/details/52981041
今日推荐