Java技术总结

来源:互联网 发布:手机上淘宝聊天记录 编辑:程序博客网 时间:2024/06/04 18:36

点击按钮进入另一个页面

<input type="button"value="开启直播" class="start myfancy" id="#m-code3"onclick="window.location.href='/channel/gotoChannel'">

 

点击超链接,执行js函数

<a onclick="javacript:alertWindow();">高级设置</a>

<a href="javacript:alertWindow();">高级设置</a>

 

格式化时间

<%@ taglib prefix='fmt'uri="http://java.sun.com/jsp/jstl/fmt" %>

<fmt:formatDatevalue="${rList.channelCreateTimes }" type="both"/>

 

定时器:

* cron表达式:* * * * * *(共6位,使用空格隔开,具体如下)

     * cron表达式:*(秒0-59) *(分钟0-59)*(小时0-23) *(日期1-31) *(月份1-12或是JAN-DEC) *(星期1-7或是SUN-SAT)

@Scheduled(cron ="0 59 * * * *")每59分钟检查一次

 

package com.wizincloud.job;

import java.util.Date;

import java.util.List;

import javax.annotation.Resource;

importorg.springframework.scheduling.annotation.Scheduled;

importorg.springframework.stereotype.Component;

import com.wizincloud.base.user.model.Unit;

importcom.wizincloud.base.user.service.UnitService;

 

/**

 * 判断用户状态定时器

 * 每天凌晨1点检查重置用户状态

 *@author wcq

 *

 */

@Component

public class UserStatusStatisticsJob {

         @Resource

         privateUnitService unitService;

        

         //每天凌晨1点执行

         @Scheduled(cron= "0 0 1 * * ?")

         publicvoid run(){

                   updateUserStatus();

         }

        

         publicvoid updateUserStatus(){

                   List<Unit>list = unitService.getUnitList();

                   for(Unit unit : list) {

                            DateexpirationTimes = unit.getExpirationTimes();

                            Datedate = new Date();

                            if(expirationTimes!=null&& (expirationTimes.getTime() <= date.getTime())){

                                     unit.setStatus(0);

                                     unitService.updateUnit(unit);

                            }

                   }

         }

}

 

页面中包含另一个页面

<%@ includefile="/WEB-INF/jsp/common/login_register_top.jsp"%>

 

页面加载时初始化js

$(document).ready(function(){

      

    });

或:

$(function(){

          

       });

 

异常:'java.lang.String' to required type 'java.util.Date'

default message [Failed to convert propertyvalue of type 'java.lang.String' to required type 'java.util.Date' for property

解决:

在Controller类中添加:

/**

     * 初始化数据的时候,进行数据类型转换,把String类型转为Date类型

     * @param binder

     */

    @InitBinder  

   publicvoidinitBinder(WebDataBinder binder) {  

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");  

        dateFormat.setLenient(true);  

        binder.registerCustomEditor(Date.class,newCustomDateEditor(dateFormat,true));  

    }

Js中String转换为Date

var st_date=$("#datepicker-example1").val();

           var st_time=$("#st_time").val();

           var year=st_date.substr(0,4);

           var month=st_date.substr(5,2)-1;

           var day=st_date.substr(8,2);

           var step=st_time.indexOf(":");

           var hours=st_time.substr(0,step);

           var second=st_time.substring(step+1);

           var date =new Date(year, month, day,hours,second);

 

radio传值

<labelfor="start1"><inputtype="radio"id="start1"name="chatType"class="checkbox"value="0"checked>开启</label>

                                                   <labelfor="close1"><inputtype="radio"id="close1"name="chatType"class="checkbox"value="1">关闭</label>

radio按钮从后台获取值:

setType('barrageType','${channel.barrageType}');

    function setType(typeName,typeValue){

       var obj=document.getElementsByName(typeName);

       for(vari=0;i<obj.length;i++){

           if(obj[i].value==typeValue){

              obj[i].checked='checked';

           }

       }

    }

radio传值到后台:

var chatType = document.getElementsByName("chatType"); 

        for (i=0; i<chatType.length; i++){ 

            if (chatType[i].checked) { 

                params["chatType"]=chatType[i].value;

            } 

       } 

Radio设置样式-传值

       .radiobox.checkbox{width:14px;height:14px;margin-right:11px;margin-left:11px;background:none;border:1px solid #808080;vertical-align:middle;  

           -webkit-border-radius:50%;

           -moz-border-radius:50%;

           border-radius: 50%;

           -webkit-appearance:none;

           -moz-appearance: none;

           appearance: none;

       }

       .radiobox.checkbox:checked{background-color:#f3b100;border-color:#f3b100;}

<!-- <inputtype="radio" id="playback" name="playback"class="checkbox" value="Y"onclick="playbackSwitch();">打开

                                  <input type="radio" id="playback"name="playback" class="checkbox"value="N"onclick="playbackSwitch();">关闭 -->

获取值:

//var playback = document.getElementsByName("playback"); 

       /*  for (i=0;i<playback.length; i++) { 

            if (playback[i].checked) { 

                playBackEnable=playback[i].value;

            } 

        }  */

                                 

Ajax提交时datetype:

dataType  期望服务器的的回应的类型。null、"xml"、"script"或者"json"其中之一。dataType提供一种方法,它规定了怎样处理服务器的响应。这个被直接地反映到jQuery.httpData方法中去。下面的值被支持:  'xml':如果dataType== 'xml',将把服务器响应作为XML来对待。同时,如果“success”回调方法被指定,将传回responseXML值 'json':如果dataType == 'json',服务器响应将被求值,并传递到“success”回调方法,如果它被指定的话。  'script':如果dataType== 'script',服务器响应将求值成纯文本。默认值:null(服务器返回responseText值)

微信公众平台

https://mp.weixin.qq.com/wiki

分享给朋友:

<!-- <scripttype="text/javascript"src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>-->

<!-- <script>

   $(document).ready(function(){

        initPage();

   });

   function initPage() {

       vartitle=$("#title").val();

       varcontent=$("#content").val();

       varshareUrl=$("#shareUrl").val();

      

        alert(window.location.href);//用于获得当前连接url/

        //用户点击分享到微信圈后加载接口接口/

       $.post("http://xxxxxxx.xxxxx.xxx/demo/wm/share.do",{"url":window.location.href},function(data,status){

            data=eval("("+data+")");

            console.log(data.appid+""+data.timestamp+" "+data.nonceStr+""+data.signature);

            wx.config({

                debug:true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。

               appId: '', // 必填,公众号的唯一标识

               timestamp: , // 必填,生成签名的时间戳

               nonceStr: '', // 必填,生成签名的随机串

               signature: '',// 必填,签名,见附录1

                jsApiList: [  // 必填,需要使用的JS接口列表,所有JS接口列表见附录2

                    'checkJsApi',

                    'onMenuShareTimeline',

                    'hideOptionMenu',

                ]

            });

            var shareTitle = "一起分享吧!";

            var shareImg ="http://imgsrc.baidu.com/baike/pic/item/509b9fcb7bf335ab52664fdb.jpg";

            wx.ready(function(){

                alert("准备分享");

                wx.onMenuShareTimeline({

                    title : shareTitle, //分享标题

                    link : '', // 分享链接

                    imgUrl : shareImg, //分享图标

                    success : function() {

                        // 用户确认分享后执行的回调函数

                        alert("分享成功");

                    },

                    cancel : function() {

                        // 用户取消分享后执行的回调函数

                        alert("分享取消");

                    }

                });

                //wx.hideOptionMenu();/***隐藏分享菜单****/

            });

        });

   }

</script> -->

input改变事件

<inputtype="text"name="email"id="email"placeholder="常用邮箱号码"class="input" >

<spanclass="m-error"id="emailSpan"style="display:none;"><iclass="icon4"></i></span>

 

$("#email").on('input',function(e){

           if ($(".m-error").show()) {

              $(".m-error").hide();

           }

       });

My97DatePicker日历日期插件

http://www.my97.net/dp/demo/index.htm

 

异常

不能加#

 

yyyy-MM-dd HH:mm:ss

HH:24小时制,hh:12小时制

 

Checkbox点击触发事件:

<div>

                         <inputtype="checkbox"id="protocol"oninput="checkProtocol();"><spanstyle="color:gray;">已阅读</span><ahref="/protocol.html">《智研直播用户服务协议》</a>

                     </div>

                     <divstyle="float:right;margin-right:25px;">

                         <span id="protocolSpan"class="protocolSpan"style="color:red;display:none;">请同意用户服务协议</span>

                      </div>

 

 

$("#protocol").change(function(){

                            if($("#protocolSpan").show()) {

                                     $("#protocolSpan").hide();

                            }

                   });

function checkProtocol(){

           var flag=$("input[type='checkbox']").is(':checked');

           var protocolSpan=document.getElementById("protocolSpan");

           if(flag==true){

              return true;

           }else{

              protocolSpan.style.display="block";

              return false;

           }

       }

图片裁剪

http://blog.csdn.net/cuixiping/article/details/45966177 

http://www.zhangxinxu.com/wordpress/2010/05/%E5%9B%BE%E7%89%87%E6%97%8B%E8%BD%AC%E5%89%AA%E8%A3%81js%E6%8F%92%E4%BB%B6%E5%85%BC%E5%AE%B9%E5%90%84%E6%B5%8F%E8%A7%88%E5%99%A8/

使用URL传递参数:

注意中文乱码问题,需要进行格式转换

var url=........;url=encodeURI(url); url=encodeURI(url); //最重要的部分,两次调用encodeURI ,就是编码两次然後在跳转到url所在的类, 获取这个参数的方法如下:String name=request.getParameter("name"); name=URLDecoder.decode(name,"utf8"); 

图片裁剪

<!-- <divclass="jc-demo-box" style="width:120px;height:120px;">

         <imgsrc="/resource/images/gimg2.jpg" id="target" alt="[JcropExample]" style="width:120px;height:120px;"/>

<div id="preview-pane">

          <divclass="preview-container">

                   <imgsrc="/resource/images/gimg2.jpg" class="jcrop-preview"alt="Preview" />

           </div>

         </div>

</div> -->

 

<scripttype="text/javascript">

  jQuery(function($){

 

    // Create variables (in this scope)to hold the API and image size

    var jcrop_api,

        boundx,

        boundy,

 

        // Grab some information about thepreview pane

        $preview = $('#preview-pane'),

        $pcnt = $('#preview-pane .preview-container'),

        $pimg = $('#preview-pane .preview-containerimg'),

 

        xsize = $pcnt.width(),

        ysize = $pcnt.height();

   

    $('#target').Jcrop({

      onChange: updatePreview,

      onSelect: updatePreview,

      setSelect: [12,12,128,128],

      aspectRatio: xsize / ysize

    },function(){

      // Use the API to get the real imagesize

      var bounds =this.getBounds();

      boundx = bounds[0];

      boundy = bounds[1];

      // Store the API in the jcrop_apivariable

      jcrop_api = this;

 

      // Move the preview into the jcropcontainer for css positioning

     $preview.appendTo(jcrop_api.ui.holder);

    });

 

    function updatePreview(c)

    {

      if (parseInt(c.w) > 0)

      {

        var rx = xsize / c.w;

        var ry = ysize / c.h;

 

        $pimg.css({

          width: Math.round(rx *boundx) + 'px',

          height: Math.round(ry *boundy) + 'px',

          marginLeft: '-' +Math.round(rx * c.x) + 'px',

          marginTop: '-' +Math.round(ry * c.y) + 'px'

        });

      }

    };

 

  });

 

 

</script>

<styletype="text/css">

 

/* Apply these styles only when#preview-pane has

  been placed within the Jcrop widget */

.jcrop-holder#preview-pane{

 display:block;

 position:absolute;

 z-index:200;

 top:10px;

 right:-10px;

 padding:6px;

 border:1px rgba(0,0,0,.4) solid;

 background-color:white;

 

 -webkit-border-radius: 6px;

 -moz-border-radius:6px;

 border-radius:6px;

 

 -webkit-box-shadow:1px 1px 5px 2px rgba(0, 0, 0, 0.2);

 -moz-box-shadow:1px 1px 5px 2px rgba(0, 0, 0, 0.2);

 box-shadow:1px 1px 5px 2px rgba(0, 0, 0, 0.2);

}

 

/* The Javascript code will setthe aspect ratio of the crop

  area based on the size of the thumbnail preview,

  specified here */

#preview-pane.preview-container{

 width:100px;

 height:100px;

 overflow:hidden;

}

 

</style>

异常:发送post请求接口:

发送带中文的参数时:

发送 POST 请求出现异常!java.io.IOException:Server returned HTTP response code: 403 for URL:

解决:参数出错

 

字符串中替换字符:

str.replace('原字符', '新字符');

空字符传递:

String类型为空,Controller中接收为””

Long ------------------------------------------ null

对象 ------------------------------------------ null

 

 

过滤字符串

将某些字符全部替换:

String newStr=str.replaceAll("&nbsp", "").replaceAll("%/*", "")

Ajax提交

$.ajax({

                  type: "POST",

                  url:" ",

                  async: true,

                  data:,

                  dataType:'json',

                  success:function(data){

                    

                   },

                   error:function() {

 

                  }

              });

Post提交

$.post(

"url",

{suggest:txt},

function(result){

   

      }

);

使用c:forEach传递同id属性的参数

<c:forEachitems="${channelDetailsList }"var="cList"varStatus="i">

    <tr>

          <td>${cList.channelName }</td>

          <td>${cList.compere }</td>

          <td>

         <aonclick="javascript:convert(${i.index+1 });">转存</a>

         </td>

</tr>

 <inputtype="hidden"id="fileUrl${i.index+1}"value="${cList.shareUrl}">

 <inputtype="hidden"id="fileName${i.index+1}"value="${cList.channelName}">

<inputtype="hidden"id="fileSize${i.index+1}"value="${cList.fileSize}">

</c:forEach>

 

function convert(str){

       var channelId=$("#channelId").val();

       var fileUrl=$("#fileUrl"+str).val();

       var fileName=$("#fileName"+str).val();

       var fileSize=$("#fileSize"+str).val();

       $.post(

               "/unloading/convert",

                "channelId="+channelId+"&fileUrl="+fileUrl+"&fileName="+fileName+"&fileSize="+fileSize,

               function(result){

                   //alert("转存成功");

                   window.location.href="/unloading/list";

               }

           );

    }

                            

0 0