java学习

java学习

 

InitializingBean与DisposableBean总结

当想让系统启动时就执行的代码,可以有2中方法实现:
1.让一个类实现InitializingBean接口,重写afterPropertiesSet()方法 ,再把这个类交给spring管理,定义为一个bean,这样就可以了
2.在一个类中自己写一个方法,此方法是无参数的,把这个类交给spring管理,定义init-method="自己定义的方法名",这样也可以,这个接触了对spring的依赖
当系统管理时执行的代码可以这样实现:
让一个类实现DisposableBean接口,重写 destroy()方法,再把这个类交给spring管理,

posted @ 2012-11-20 13:35 杨军威 阅读(383) | 评论 (0)编辑 收藏

extjs中选中一行

typeGrid.on('rowclick', function(grid, rowIndex, event) {
  currRecord = grid.getStore().getAt(rowIndex);
 });

typeGrid是数据类表的面板,currRecord 是这一行的对象


posted @ 2012-11-08 16:20 杨军威 阅读(458) | 评论 (0)编辑 收藏

extjs的分页感悟

 

Extjs中分页的使用:

在后台查询程序中查询出的数据集合要放在一个辅助类的对象中辅助类要有2个属性,一个放数据总数,一个房数据集合,例如:

public class DirectStore {

 

    private int totalRecords;

    private final List<?> results;

 

    public DirectStore(final int totalRecord, final List<?> results) {

       super();

       this.totalRecords = totalRecord;

       this.results = results;

    }

 

    public List<?> getResults() {

       return this.results;

    }

 

    public int getTotalRecord() {

       return this.totalRecords;

    }

 

    public void setTotalRecord(final int totalRecord) {

       this.totalRecords = totalRecord;

    }

 

    @Override

    public String toString() {

       return "{'totalRecords':" + this.totalRecords + ",'results'"

              + this.results + "}";

    }

 

}

把查询出的额数据集合放在对象中

DirectStore store = new DirectStore(recordNumber, list);

ext的页面中,需要先定义如下:

var typeStore = new Ext.data.DirectStore({

       paramOrder : [ 'start', 'limit' ],

       baseParams : {

           'start' : 0,

           'limit' : 20

       },

       root : 'results',

       totalProperty : 'totalRecords',//DirectStore对象的totalRecords属性一样

       idProperty : 'id',

       fields : [ 'id', 'name', 'Unit', 'description' ],//集合中存放的对象的属性

       directFn : EamDjn.getDepartment

    });

    typeStore.load();

再在页面下面写:

bbar: new Ext.PagingToolbar({

           pageSize: 20,

           store : typeStore,

           displayInfo: true,

           displayMsg: '显示第 {0} 条到 {1} 条记录,一共 {2} ',

           emptyMsg: '没有记录'

       })

这样就完成分页了,需要

posted @ 2012-11-08 16:17 杨军威 阅读(490) | 评论 (0)编辑 收藏

extTree

function tree3(){
    var root=new Ext.tree.TreeNode({
      id:"root",
      href:"http://www.easyjf.com",
       hrefTarget:"_blank",
      text:"树的根"});
    var c1=new Ext.tree.TreeNode({
      id:"c1",
      href:"http://www.easyjf.com",
       hrefTarget:"_blank",
      text:"一级子节点1"
      });
    var c2=new Ext.tree.TreeNode({
      id:"c2",
      href:"http://www.easyjf.com",
       hrefTarget:"_blank",
      text:"一级子节点2"
      });
    var c3=new Ext.tree.TreeNode({
      id:"c3",
      href:"http://www.easyjf.com",
       hrefTarget:"_blank",
      text:"二级子节点1"
      });
    var c4=new Ext.tree.TreeNode({
      id:"c4",
      href:"http://www.easyjf.com",
       hrefTarget:"_blank",
      text:"二级子节点2"
      });
    root.appendChild(c1);
    root.appendChild(c2);
    c1.appendChild(c3);
    c2.appendChild(c4);
    var tree=new Ext.tree.TreePanel({
      renderTo:"hello",
      root:root,
      width:200
      });
    root.on("click",function(node,event){
      alert("您点击了"+node.text);
              }
          );
    c1.on("click",function(node,event){
      alert("您点击了"+node.text);
            }
     );
    c2.on("click",function(node,event){
      alert("您点击了"+node.text);
            }
     );
    c3.on("click",function(node,event){
      alert("您点击了"+node.text);
            }
     );
    c4.on("click",function(node,event){
      alert("您点击了"+node.text);
            }
     );    
   }

posted @ 2012-10-23 15:30 杨军威 阅读(510) | 评论 (0)编辑 收藏

ext 学习笔记

     摘要: <html>    <head>        <link rel="stylesheet" type="text/css" href="ext-3.3.1\resources\css/ext-all.css" />     &nbs...  阅读全文

posted @ 2012-10-23 09:55 杨军威 阅读(472) | 评论 (0)编辑 收藏

get请求中文乱码问题的解决

在tomcat的conf文件夹中的server.xml文件中找到<Connector>节点,在节点中写上URIEncoding="UTF-8",就可以解决整个项目中的get请求的中文乱码

posted @ 2012-09-27 16:47 杨军威 阅读(257) | 评论 (0)编辑 收藏

hibernate里的DetachedCriteria的几种条件查询方法

detachedCriteria.add(Restrictions.eq("user.userId", userId));
Restrictions.eq()是等于,Restrictions.allMap()使用Map,使用key和value进行多个等于的对比
Restrictions.gt()大于,Restrictions.ge()大于等于,Restrictions.lt()小于,
Restrictions.le()小于等于,Restrictions.between()对应sql中的between字句,
Restrictions.like()对应sql的like字句,
Restrictions.in()对应sql的in字句
Restrictions.and()
Restrictions.or()
Restrictions.sqlRestnction(),是对sql限定查询 

posted @ 2012-09-27 13:35 杨军威 阅读(722) | 评论 (0)编辑 收藏

中文字符转码

1.    String s = “中文”;
S = new String(s.getBytes(“ISO8859-1”),”utf-9”);
2.    使用过滤器:
public class CharsetFilter implements Filter{

    private String encoding = "UTF-8";
    
    public void destroy() {
        
    }

    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding(encoding);
        chain.doFilter(request, response);
    }

    public void init(FilterConfig filterConfig) throws ServletException {
        String encoding = filterConfig.getInitParameter("encoding");
        if(encoding != null) {
            this.encoding = encoding;
        }
    }

}
3.request.setCharacterEncoding(“utf-8”);

posted @ 2012-05-04 21:55 杨军威 阅读(1910) | 评论 (0)编辑 收藏

内存溢出解决方案

找到自己的myeclipse安装目录,找到文件myeclipse.ini,改最后三项数据
-Xmx1024m
-XX:MaxPermSize=1024
-XX:ReservedCodeCacheSize=512m,再重做tomcat就好了

posted @ 2012-05-04 15:25 杨军威 阅读(154) | 评论 (0)编辑 收藏

用配置事务

在applicationContext.xml里写:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:p
="http://www.springframework.org/schema/p"
         xmlns:aop
="http://www.springframework.org/schema/aop"
         xmlns:tx
="http://www.springframework.org/schema/tx"
       xmlns:context
="http://www.springframework.org/schema/context"
       xsi:schemaLocation
="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd

">
<!-- 使用注解支持事务
<tx:annotation-driven transaction-manager="transactionManager" />   -->
<!-- 添加jdbc的任务管理器 -->
<bean  id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 配置事务通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
    
<tx:attributes>
        
<!-- name表示以什么开始的方法名,比如 add*表示add开头的方法
            propagation表示事务传播属性,不写默认有
         
-->
         
<tx:method name="save*" propagation="REQUIRED"/>
         
<tx:method name="del*" />
         
<tx:method name="update*"/>
         
<tx:method name="find*"  read-only="true"/>
    
</tx:attributes>
</tx:advice>
<!-- 配置事务切面 -->
<aop:config>
    
<aop:pointcut expression="execution(* com.yjw.service..*.*(..))" id="pointcut"/>
    
<aop:advisor advice-ref="txAdvice"  pointcut-ref="pointcut"/>
</aop:config>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass"  value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl"  value="jdbc:mysql:///mydb"/>
<property name="properties">
<props>
    
<prop key="user">root</prop>
    
<prop key="password">root</prop>
    
</props>
</property>
</bean>
<bean id="simpleJdbcTemplate"  class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
    
<constructor-arg ref="dataSource"></constructor-arg>
</bean>
<!-- 在使用事务时不能配置jdbc模板,只能配置数据流 -->
<bean  id="userdao" class="com.yjw.dao.UserDao">
    
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="userService"  class="com.yjw.service.UserService">
    
<!-- name的值只和set方法后面的有关,要一样 -->
    
<property name="dao"  ref="userdao"></property>
</bean>
</beans>
在service里写:
public class UserService {

    
private  UserDao  userdao;
    
    

    
public void setDao(UserDao userdao) {
        
this.userdao = userdao;
    }

    
    
public  void  save(User user){
        userdao.save(user);
        
if(true){
            
throw new  RuntimeException();
        }

    
        userdao.save(user);
    }

    
//只读,会使性能提高,推荐使用
    
//@Transactional(readOnly=true)
    public  User findById(int id){
        
return userdao.findById(id);
    }

}

posted @ 2012-05-03 22:17 杨军威 阅读(1678) | 评论 (0)编辑 收藏

仅列出标题
共43页: First 上一页 35 36 37 38 39 40 41 42 43 下一页 

导航

统计

常用链接

留言簿

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜