java问题小结

来源:互联网 发布:360医药软件 编辑:程序博客网 时间:2024/05/17 08:08
  1. Tomcat 访问地址应不包含服务名
    这里写图片描述

  2. NoClassDefFoundError:
    NoClassDefFoundError错误的发生,是因为Java虚拟机在编译时能找到合适的类,而在运行时不能找到合适的类导致的错误。

  3. org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map
    这是因为在另一个Mapper.xml里将parameterType写成了parameterMap

  4. 断点调试的时候报source not found:把断点打到下一句,可能是事务
    控制

  5. eclipse “Alt+Enter” 设置Text file encoding 为GBK,解决文档注释
    乱码问题:
    这里写图片描述

  6. eclipse远程调试在controller 增加代码时,不用重启服务,只需要
    加一行空格,重新编译

  7. myBatis 生成mapper文件,dao层如果只有insert,可能是表里没有
    主键.

  8. java list add对象空指针:List没有实例化,需要new.

  9. 批量插入的时候:
    oracle不是自动提交,需要commit;
    mysql是自动提交,不需要commit,若需提高效率,则需将自动提交事
    务关闭;
  10. 返回前台页面形式:
    action(controller)中用response.getWriter()输出json字符串。
    ajax接收后,在success方法中:
    var jsonObj = eval(json);// 将json字符串转换成json对象。
    比如action中返回{‘flag’:’success’},ajax的success方法中:
    `var jsonObj = eval(json);
  11. resphonse.write()就是直接把内容写到页面
    resphonse.getwrite().write()就是返回个响应再把内容写到页面

  12. 遍历map/list:
    <1>
    Set<Map.Entry> entrySet = map.entrySet();
    for (Map.Entry entry : entrySet) {
    entry.getKey();
    entry.getValue();
    }

    <2>
    for(int i = 0 ; i < resList.size() ; i++) {
    Map<String,Object> bg = new HashMap<String,Object>();
    Map map = (Map)resList.get(i);
    bg.put("BG", map.get("bg")); //指标文号
    list.add(bg);
    }

  13. Map 拼接两个value:
    map.put(*,new Object[]{map.get(“key”),map.get(“key”)});
  14. Json类型转换:
    String params = request.getParameter(“param”);

    //将字符串转为对象
    JSONObject object = JSONObject.fromObject(params);

    //定义map
    Map<String,Object> paramMap = new HashMap<String,Object>();
    //将对象转换为map
    paramMap =(Map) object;

    //根据属性名获得属性值
    String ss =
    object.getClass().getDeclaredField("commSign").get(object).toString();

    // 得到类对象
    Class userCla = (Class) obj.getClass();
    /* 得到类中的所有属性集合 */
    Field[] fs = userCla.getDeclaredFields();

    获取封装对象内容:
    List<MaEleBgItemVo> insList = null;
    insList.get(i).getEleCode().equals("SUBSIDYLEVERLS")

  15. 获取前台页面传过来的值:
    String params = request.getParameter(“param”);

  16. 日期格式化:
    SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
    Date date=new Date();
    String tempDate = dateFormater.format(date);
    try {
    svDate = dateFormater.parse(tempDate);
    } catch (ParseException e) {
    e.printStackTrace();
    }

  17. super():
    super可以理解为是指向自己超(父)类对象的一个指针,而这个超类指的是离自己最近的一个父类。
    *从本质上讲,this是一个指向本对象的指针, 然而super是一个Java关键字

  18. 判断字符串是否相等“:
    String str1="abc";
    String str2=“bcd";
    if(str1.equals(str2)){
    system.out.println("str1和str2相等”);

  19. 判断非空;
    StringUtil.isNull(ins);

  20. 判断类型
    //判断insTypeCode是否为多个
    List insTypeCodeList = new ArrayList();
    Object insTypeCode = map.get(“insTypeCode”);
    map.remove(“insTypeCode”);
    if (insTypeCode instanceof CharSequence) {
    map.put(“insTypeCode”, insTypeCode);
    } else if (insTypeCode instanceof Collection) {
    insTypeCodeList = (List) insTypeCode;
    map.put(“insTypeCodeList”, insTypeCodeList);
    }

    Mapper:如果insTypeCodeList不为null
    <if test="insTypeCodeList != null">
    and S.INSURANCE in
    <foreach collection="insTypeCodeList" item="item" separator="," close=")" open="(">
    #{item}
    </foreach>
    </if>

  21. 保留两位小数:
    DecimalFormat df = new DecimalFormat(“#.00”);
    df.format(某参数);

  22. 取某一行的xxx字段:
    StringUtil.getFieldListFromRowList(rows,”xxx”)

  23. classnotdefined可能是没有把包打到域里