总结(1)

获取省份列表在许多页面用到的比较多,可以单独出来,写一个方法.

public List getProvinceList(HttpServletRequest request){
List list = this.getServiceFacade().getProvince();
request.setAttribute("proList", list);
return list;
}


页面判断数据的有无时,采用同一属性值判断.
<login:notEmpty name="value">
</login:notEmpty>


<logic:empty name="value">
</logic:empty>

密码修改(ibatis)

select password('newpassword') as password

登陆模块,将整个account的信息封闭在session里,以便于其它内容需要时提供


任何取到的数据或参数,为了数据安全,都要判断.

String tip = request.getParameter("tip");
if(tip!=null&&"".equals(tip)){
//related codes
}

String 转 int ,建议采用以下方法.

String number = "12";
int num = Integer.valueOf(number);
//int mub = Integer.parseInt(number);

String number = "31";
int num = new Integer(number);
//int num = Integer.valueOf(number).intValue();



如果采用struts,表单的验证尽量有validate完成.


Struts action中不作业务处理,只将数据封装后,传输到service端进行业务逻辑操作.

for example:

//this.getServiceFacade().updateAccountInfo(address,person);
以上code同时更新两个数据表内容.

service:
update(address);
update(person);


mysql ,关联数据表进行写入操作时,被引用的表先进行,然后进行子表的写入.

int id = insert(father table);
insert(child table,id);


Dao层返回数据的时候,可以先进行简单的处理.[同样适用于页面逻辑的处理]

return (list==null?(new ArrayList(0)):list);
//返回一个空对象.不是null,null容易引起错误.


List泛型的使用.

能确定类型的尽量为list引入泛型.

list<Account> accout = this.getAccountList();
//这样查询出来的list就是Account类型的,而不再需要为其进行强制类型的转换.


方法重写或失效时可以用 [@Deprecated ] 注释掉.



struts.xml文件中.可以配置<forward redirect="true"/>直接使用forwart同样达到sendRedirect的效果.

成长的乐趣,在于分享!
大龄程序员,一路走来,感慨颇多。闲暇时写写字,希望能给同行人一点帮助。
本文版权归作者growithus和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/growithus/p/11012506.html