java學習

          java學習

           

          InitializingBean與DisposableBean總結

          當想讓系統啟動時就執行的代碼,可以有2中方法實現:
          1.讓一個類實現InitializingBean接口,重寫afterPropertiesSet()方法 ,再把這個類交給spring管理,定義為一個bean,這樣就可以了
          2.在一個類中自己寫一個方法,此方法是無參數的,把這個類交給spring管理,定義init-method="自己定義的方法名",這樣也可以,這個接觸了對spring的依賴
          當系統管理時執行的代碼可以這樣實現:
          讓一個類實現DisposableBean接口,重寫 destroy()方法,再把這個類交給spring管理,

          posted @ 2012-11-20 13:35 楊軍威 閱讀(389) | 評論 (0)編輯 收藏

          extjs中選中一行

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

          typeGrid是數據類表的面板,currRecord 是這一行的對象


          posted @ 2012-11-08 16:20 楊軍威 閱讀(466) | 評論 (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 楊軍威 閱讀(502) | 評論 (0)編輯 收藏

          extTree

          function tree3(){
              var root=new Ext.tree.TreeNode({
                id:"root",
                href:"       hrefTarget:"_blank",
                text:"樹的根"});
              var c1=new Ext.tree.TreeNode({
                id:"c1",
                href:"
                 hrefTarget:"_blank",
                text:"一級子節點1"
                });
              var c2=new Ext.tree.TreeNode({
                id:"c2",
                href:"
                 hrefTarget:"_blank",
                text:"一級子節點2"
                });
              var c3=new Ext.tree.TreeNode({
                id:"c3",
                href:"
                 hrefTarget:"_blank",
                text:"二級子節點1"
                });
              var c4=new Ext.tree.TreeNode({
                id:"c4",
                href:"
                 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 楊軍威 閱讀(517) | 評論 (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 楊軍威 閱讀(483) | 評論 (0)編輯 收藏

          get請求中文亂碼問題的解決

          在tomcat的conf文件夾中的server.xml文件中找到<Connector>節點,在節點中寫上URIEncoding="UTF-8",就可以解決整個項目中的get請求的中文亂碼

          posted @ 2012-09-27 16:47 楊軍威 閱讀(262) | 評論 (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 楊軍威 閱讀(773) | 評論 (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 楊軍威 閱讀(1937) | 評論 (0)編輯 收藏

          內存溢出解決方案

          找到自己的myeclipse安裝目錄,找到文件myeclipse.ini,改最后三項數據
          -Xmx1024m
          -XX:MaxPermSize=1024
          -XX:ReservedCodeCacheSize=512m,再重做tomcat就好了

          posted @ 2012-05-04 15:25 楊軍威 閱讀(202) | 評論 (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 楊軍威 閱讀(1685) | 評論 (0)編輯 收藏

          僅列出標題
          共43頁: First 上一頁 35 36 37 38 39 40 41 42 43 下一頁 

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 玉林市| 高要市| 桦川县| 孟村| 浏阳市| 舒兰市| 囊谦县| 北宁市| 五指山市| 阳西县| 嘉义市| 沛县| 普陀区| 安丘市| 信宜市| 丹寨县| 水城县| 金沙县| 池州市| 定襄县| 陆良县| 林甸县| 达日县| 余江县| 化德县| 永登县| 泌阳县| 新河县| 垦利县| 广安市| 芷江| 分宜县| 吉隆县| 河西区| 林甸县| 颍上县| 黄山市| 祁东县| 永登县| 小金县| 孝感市|