2009年1月20日

          IoC   :   Inversion of Control

          spring是通過依賴注入(Dependency Injection )實現的IoC

          IoC容器

             *   必須將被管理的對象定義到spring配置文件中
             *   必須定義constructor或者setter方法,讓spring將對象注入進去

          AOP  :  Aspect Oriented Programming

          spring帶來了一種編程方式,面向切面的編程。

          AOP是一個概念

          在一個程序中分離一個功能,這種功能的實現是與程序不相關的類。
          同時能夠使很多類共享這個功能。

          關注是他的主要點,要關注某個功能,要關注切入點。

          實現AOP有2點:
          1、Pointcut(切入點)是一個范圍---表達式
          2、Advice(具體實現)功能放到那個方法



          spring對hibernate的支持

          注入SessionFactory到spring配置文件中

          <Bean id="SessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactory">
                  <property nema="configLocation">
                          <value>classpath:hibernate.cfg.xml</value>
                  </property>
          </Bean>

          posted @ 2009-02-13 08:40 天長 閱讀(129) | 評論 (0)編輯 收藏
           
          在庫中建表時語句為: create table tbname(..........)engine=MyISAM character set gbk collate gbk_chinese_ci;


          程序中連接數據庫的Connection對象需要寫成Connection con = DriverManaager.getConnection("jdbc:mysql://...user=..&password=...&useUnicode=true&characterEncoding=gbk");
          若在終端下用mysql命令向數據庫插入數據,則在進入mysql時的命令寫成:#mysql --default-character-set=gbk -u ... -p

          在網上看過很多解決mysql亂碼的帖子,可是寫的不是羅里羅嗦就過于復雜。其實亂碼沒那么復雜,是網上的大俠們想多了。我研究過一段日子,總結出一套自己的解決方案,如果你還沒解決亂碼就用我的方法試一下。我的方案不是最好的,卻是最簡單易懂的。不信你試試。

          在使用MYSQL時,插入中文字符,經常會出現亂碼,中文全被用?代替。出現這種情況的原因,多是字符集不匹配造成的。
          在MYSQL中,如果使用缺省的字符集,在建庫、建表時,默認使用的是latin1字符集,為ISO 8859-1西歐字符集。插入中文字符時,與之不匹配,就會出現亂碼。

          要解決此問題,就必須手動將數據庫Server和Client的字符編碼改為gb2312。配置方法如下:
          打開MYSQL安裝目錄下的my.ini文件,找到如下段落:

          # CLIENT SECTION
          # ----------------------------------------------------------------------
          #
          # The following options will be read by MySQL client applications.
          # Note that only client applications shipped by MySQL are guaranteed
          # to read this section. If you want your own MySQL client program to
          # honor these values, you need to specify it as an option during the
          # MySQL client library initialization.
          #
          [client]

          port=3306

          [mysql]

          default-character-set=latin1


          # SERVER SECTION
          # ----------------------------------------------------------------------
          #
          # The following options will be read by the MySQL Server. Make sure that
          # you have installed the server correctly (see above) so it reads this
          # file.
          #
          [mysqld]

          # The TCP/IP Port the MySQL Server will listen on
          port=3306

          #Path to installation directory. All paths are usually resolved relative to this.
          basedir="D:/MySQL/MySQL Server 5.0/"

          #Path to the database root
          datadir="D:/MySQL/MySQL Server 5.0/Data/"

          # The default character set that will be used when a new schema or table is
          # created and no character set is defined
          default-character-set=latin1

          將其中的default-character-set=latin1改為default-character-set=gb2312( 兩個都改),然后重啟MYSQL(特別注意:以前建立的數據庫要重建,因為以前存儲的數據編碼方式為ISO-8859-1),運行MySQL Command Line Client:
          輸入show variables like 'character_set_%';可以查看數據庫的字符編碼如下:

          mysql> show variables like 'character_set_%';
          +--------------------------+-----------------------------------------+
          | Variable_name             | Value                                     |
          +--------------------------+-----------------------------------------+
          | character_set_client      | gb2312                                   |
          | character_set_connection | gb2312                                |
          | character_set_database    | gb2312                                |
          | character_set_filesystem | binary                                   |
          | character_set_results     | gb2312                                   |
          | character_set_server      | gb2312                                  |
          | character_set_system      | utf8                                     |
          | character_sets_dir        | D:\MySQL\MySQL Server 5.0\share\charsets|
          +--------------------------+-----------------------------------------+

          然后,在程序中將連接數據庫的URL改為jdbc:mysql://localhost:3306/databasename?useUnicode=true&amp;characterEncoding=gb2312   就可以了!(&amp;是代表xml中的&)

          還需要注意到是:1.你的JSP頁面一定別忘了加上編碼方式<%@ page pageEncoding="GB2312"%>。

          2.把以前寫過濾方法如:getbytes(iso-8859-1)全去掉

          最后記住,一定要重新導入或建立數據庫!!!

          posted @ 2009-01-20 07:19 天長 閱讀(143) | 評論 (0)編輯 收藏
           
          主站蜘蛛池模板: 科尔| 东港市| 临泉县| 阜城县| 伊宁市| 蓬安县| 嘉定区| 崇阳县| 昭苏县| 泊头市| 东乌珠穆沁旗| 庆元县| 耒阳市| 新安县| 台南县| 秦安县| 蓝田县| 万山特区| 防城港市| 江油市| 杨浦区| 神池县| 积石山| 上思县| 屏南县| 巩留县| 芜湖县| 轮台县| 含山县| 娱乐| 博罗县| 泽库县| 白城市| 仲巴县| 南通市| 泰宁县| 蕲春县| 都匀市| 嘉峪关市| 二连浩特市| 乐都县|