工作小知识点积累

/*********前台知识***********/

1、ajax传list数组和其他对象

 

2、ajax拼接html代码时,要将参数拼接到语句中

var idInput = "<input type='hidden' name='basicquestionId' value='"+data[0].id+"'/>";

3、jquery选中单选框标签

$("#answer input[type=radio]").eq(data[0].answerId-1).attr("checked",true);

4、数组设值

1 var choiceList = new Array();
2 choiceList.push({id:null,basicquestionId:$basicquestionId,choiceId:String.fromCharCode(65+i),context:$("[name=context]").eq(i).val()});

5、js 将数字转化为字母

String.fromCharCode(65+i)

6、javascript:void(0)表示一个死链接
  #包含了一个位置信息


7、单选框非空验证

1 if($(":radio:checked").length==0){
2     layer.closeAll();
3     layer.msg("请选择答案!");
4     return false;
5 }

8、获取选中单选框的值

1 var value = $("input:radio[name=choice]:checked")val();

 9、util.js获取项目根路径

/*
 * js中获取项目根路径
 * */
webRoot = function(){
        var curWwwPath = window.document.location.href;
        var pathName = window.document.location.pathname;
        var pos = curWwwPath.indexOf(pathName);
        var localhostPath = curWwwPath.substring(0,pos);
        var projectName = pathName.substring(0,pathName.substr(1).indexOf('/')+1);
        return (localhostPath+projectName);
    };
ctx = webRoot();    
Array.prototype.indexOf = function(val){
    for(var i=0;i<this.length;i++){
        if(this[i] == val){return i;}
    }
    return -1;
}
Array.prototype.rmv = function(val){
    var index = this.indexOf(val);
    if(index > -1){
        this.splice(index, 1);
    }
}

之后的js中ctx代表根目录

10、全选和反选复选框

//全选和反选单选框
$("[name=checkAll]").click(function(){
    if(this.checked){
         $("input[name=deleteId]").each(function(){
             this.checked = true;
         });    
    }else{
         $("input[name=deleteId]").each(function(){
             this.checked = false;
         });    
    }
});    

11、页面选择好图片,并预览图片(此时页面文件还未上传)

 

//页面HTML
<img id="imgShow" src="" class="clp btn">
<input type="file" id="file" onchange="addPicture(this)">

//js
//获取文件的本地路径
function getObjectUrl(file){
  var url = null;
 if(window.createObjectURL != undefined){
    url = window.createObjectURL(file);
 }else if(window.URL != undefined){
    url = window.URL.createObectURL(file);
 }else if(window.webkitURL != undefined){
    url = window.webkitURL.createObjectURL(file);
 }
 return url;
}

//点击载入图片,展示选择的图片
function addPicture(obj){
    var objUrl = getObjectUrl(obj.file[0]);
    if(objUrl){
        
    }
}

 

/*************后台知识*****************/

1、控制器传值:通过ModelAndView来传

1 return new ModelAndView("/error",map);

2、对传进来的值进行不为空校验

if(basicknowledgeVo!=null&&!"".equals(basicknowledgeVo))

3、@ResponseBody?

 

4、业务层抛出ServiceException异常

1 public void removeBasicknowledge(Integer id) throws ServiceException

5、持久层抛出DatabaseException异常

public void deleteBasknowledge(Integer id) throws DatabaseException


6、@Repository?

 

7、web.xml中配置编码格式

1 <filter>
2 <filter-name>CharacterEncodingFilter</filter-name>
3 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
4 <init-param>
5 <param-name>encoding</param-name>
6 <param-value>utf-8</param-value>
7 </init-param>
8 </filter>

8、在applicationContext-transaction.xml中配置事务管理,只要对数据库操作的方法以下面单词开头,那么对应操作具有原子性

 1 <!-- 通知 -->
 2 <tx:advice id="txAdvice" transaction-manager="transactionManager">
 3 <tx:attributes>
 4 <!-- 传播行为 -->
 5 <tx:method name="save*" propagation="REQUIRED"/>
 6 <tx:method name="delete*" propagation="REQUIRED"/>
 7 <tx:method name="insert*" propagation="REQUIRED"/>
 8 <tx:method name="update*" propagation="REQUIRED"/>
 9 <tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
10 <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
11 <tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
12 </tx:attributes>
13 </tx:advice>

9、数字转字母

String.valueOf((char)(65+i))

10、大写字母转数字

Integer.valueOf(“A”.charAt(0))

11、Java获得UUID

String uuid = UUID.randomUUID().toString();

12、上传文件错误:

Required MultipartFile parameter 'file' is not present

13、db.properties中编码格式的设置

jdbc:mysql://127.0.0.1:3306/car_manager?useUnicode=true&characterEncoding=utf-8

14、错误:Invalid bound statement (not found)

  1、检车xml文件的namespace是否和xml文件的package名称一一对应

  2、检查函数名是否对应上

15、double是强制转换为int时,强制将小数去掉

 

/**********************************************************数据库知识*********************************************************/

1、建立下拉菜单的表(数据字段字典表)
  t_function表
  id/ename/chname/evalue/chvalue

2、删除多行数据的SQL(SQL循环)

1 <delete id="deletePaper" parameterType="List">
2 delete from t_test_paper where id in
3 <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
4 #{item}
5 </foreach>
6 </delete>



posted @ 2017-10-22 10:28  Other+  阅读(169)  评论(0)    收藏  举报