yufeng506的博客
yufeng506 · 共 11 篇文章
优化数据库的查询
虽然大部分知道,但觉得概括得挺好,转载了,一个群上帐号出来的,不知道出处... 1、程序中, 保证在实现功能的基础上,尽量减少对数据库的访问次数; 通过搜索参数,尽量减少对表的访问行数,最小化结果集,从而减轻网络负担; 能够分开的操作尽量分开处理,提高每次的响应速度; 在数据窗口使用SQL时,尽量把使用的索引放在选择的首列; 算法的结构尽量简单; 在查询时,不要过多地使用通配符如SELECT * FROM T1语句,要用到几列就选择几列如:SELECT COL1,COL2 FROM T1; 在可能的情况下尽量限制尽量结果集行数如:SELECT TOP 300 COL1,COL2,COL3 F…
2011-02-24 09:11 · 评论(0)
struts2 生成随机验证码
基于注解的方式实现的。主要代码: @Action(value = "generateRandImg", results = { @Result(name = "result", type = "stream", params = { "contentType", "image/jpeg", "inputName", "resultStream" }) }) public String generateRandImg() throws IOException { int width = 60, height = 20; BufferedImage image = new BufferedIma…
2011-01-13 16:40 · 评论(0)
spring整合hibernate 使用hibernatetemplate做查询
首先在spring的applicationContext.xml里配置hibernate的配置和hibernatetemplate。 <bean id="hibernateTemplete" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="operation" class="domain.Operation"> <!--Operation是一个Dao类-…
2011-01-12 09:43 · 评论(0)
spring的自动装配方式总结
spring的装配方式有很多种,我主要学习了下autowire=byType,byName,constructor的用法。他们的配置文件和代码如下: 类文件 public class Person { private String name; private Home myhome; public Person(Home myhome){ this.myhome = myhome; } public String getName() { return name; } public void setName(String name) { this.name = name; } public H…
2011-01-07 14:59 · 评论(0)
spring 的几个注入方式
spring是很强大的:把这几天学习的心得记录下来。 常用的有两种注入方式,set值注入,构造注入。 set注入的xml写法如下: <bean id="chinese" class="Chinese"> <property name="name" value="wanger"/> <property name="age" value="22"/> <property name="food" ref="food"/> </bean> ref是引用到别的bean <bean id="food" class="Food"> <constructor-arg index="0" value="cab…
2011-01-06 15:47 · 评论(0)
struts2 的批量删除功能完整例子
struts2 方法代码: public String batchDelete() throws UnsupportedEncodingException { simple = new SimpleCRUDImpl(); simple.doBatchDelete(ids); byte buff = "you batchdelete some record succeed!".getBytes("UTF-8"); resultStream = new ByteArrayInputStream(buff, 0, buff.length); return SUCCESS; } 页面的全选js及页面…
2011-01-05 10:37 · 评论(1)
JQuery 做的checkbox全选功能
jQuery代码: $(function() { //全选、反选 $('#chooseAll').click(function() { var list = $('').length; if ($('#chooseAll').attr("checked") == true) { for ( var i = 0; i < list; i++) { $('').attr("checked", "true"); } } else if ($('#chooseAll').attr("checked") == false) { $('').click(); } }); }); 页面HTML代码: 全选的
2011-01-05 10:31 · 评论(0)
hibernate 查询记录数 count函数
直接贴代码: public class CountTransactionDao { public int countTransaction(){ Configuration conf = new Configuration().configure(); SessionFactory sf = conf.buildSessionFactory(); Session session = sf.openSession(); // Transaction tx = session.beginTransaction(); int count = ((Number)session.createQuery…
2010-12-29 14:49 · 评论(0)
struts2 上传和下载的实现
直接贴代码 action类代码: public class UploadAction extends ActionSupport { /** * */ private static final long serialVersionUID = 1L; private File file; private String fileFileName; private String fileFileType; @SuppressWarnings("deprecation") @Override public String execute() throws Exception { InputStream…
2010-12-29 14:38 · 评论(0)
struts2 + hibernate 分页显示
action 类方法 public String view() { simple = new SimpleCRUDImpl(); PageNavigateCalculator pnc = new PageNavigateCalculator(); pnc.setTotalRowsAmount(simple.doCountTransaction()); System.out.println(pnc.getTotalRowsAmount()); pnc.setCurrentPage(page); totalpage = pnc.getTotalPages(); pre = pnc.HasPrev…
2010-12-29 14:29 · 评论(0)
struts2 异步提示修改密码成功 流的方式
public String delete() throws UnsupportedEncodingException { simple = new SimpleCRUDImpl(); simple.doDelete(news.getId()); byte buff = null; buff = "you delete news succeed".getBytes("utf-8"); resultStream = new ByteArrayInputStream(buff, 0, buff.length); return SUCCESS; } xml 配置部分 text/plain resul…
2010-12-28 16:54 · 评论(0)