-
Tomcat 访问地址应不包含服务名:
-
NoClassDefFoundError:
NoClassDefFoundError错误的发生,是因为Java虚拟机在编译时能找到合适的类,而在运行时不能找到合适的类导致的错误。 -
org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map
这是因为在另一个Mapper.xml里将parameterType写成了parameterMap -
断点调试的时候报source not found:把断点打到下一句,可能是事务
控制 -
eclipse “Alt+Enter” 设置Text file encoding 为GBK,解决文档注释
乱码问题:
-
eclipse远程调试在controller 增加代码时,不用重启服务,只需要
加一行空格,重新编译; -
myBatis 生成mapper文件,dao层如果只有insert,可能是表里没有
主键. -
java list add对象空指针:List没有实例化,需要new.
-
批量插入的时候:
oracle不是自动提交,需要commit;
mysql是自动提交,不需要commit,若需提高效率,则需将自动提交事
务关闭; -
返回前台页面形式:
action(controller)中用response.getWriter()输出json字符串。
ajax接收后,在success方法中:
var jsonObj = eval(json);
// 将json字符串转换成json对象。
比如action中返回{‘flag’:‘success’},ajax的success方法中:
`var jsonObj = eval(json); -
resphonse.write()就是直接把内容写到页面
resphonse.getwrite().write()就是返回个响应再把内容写到页面 -
遍历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); }
-
Map 拼接两个value:
map.put(*****,new Object[]{map.get(“key”),map.get(“key”)}); -
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")`
-
获取前台页面传过来的值:
String params = request.getParameter(“param”); -
日期格式化:
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(); }
-
super():
super可以理解为是指向自己超(父)类对象的一个指针,而这个超类指的是离自己最近的一个父类。
*从本质上讲,this是一个指向本对象的指针, 然而super是一个Java关键字。 -
判断字符串是否相等“:
String str1="abc"; String str2=“bcd"; if(str1.equals(str2)){ system.out.println("str1和str2相等”);
-
判断非空;
StringUtil.isNull(ins);
-
判断类型
//判断ins是否为多个
List insList = new ArrayList();
Object ins = map.get(“ins”);
map.remove(“ins”);
if (ins instanceof CharSequence) {
map.put(“in”, ins);
} else if (ins instanceof Collection) {
insList = (List) ins;
map.put(“insList”, insList);
}
Mapper:如果insList不为null
`<if test="insTypeCodeList != null">
and S.INSURANCE in
<foreach collection="insTypeCodeList" item="item" separator="," close=")" open="(">
#{item}
</foreach>
</if>`
-
保留两位小数:
DecimalFormat df = new DecimalFormat("#.00");
df.format(某参数); -
取某一行的xxx字段:
StringUtil.getFieldListFromRowList(rows,“xxx”) -
classnotdefined可能是没有把包打到域里