<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-67  評論-522  文章-0  trackbacks-0
        Spring更新到3.0之后,其MVC框架加入了一個非常不錯的東西——那就是REST它的開放式特性,與Spring的無縫集成,以及Spring框架的優(yōu)秀表現(xiàn),使得現(xiàn)在很多公司將其作為新的系統(tǒng)開發(fā)框架。大象根據(jù)實(shí)際的項(xiàng)目經(jīng)驗(yàn),以之前SSH2例子為基礎(chǔ),對其進(jìn)行一次大改造,詳細(xì)的為大家講解如何實(shí)現(xiàn)SSM3全注解式的開發(fā)。
        這次大象將采取兩種構(gòu)建方式,一是很多人喜歡用的MyEclipse,另一個,則是用Eclipse+Maven。這一篇,將主要講解開發(fā)環(huán)境設(shè)置Maven構(gòu)建方式。
        1、
    開發(fā)環(huán)境
        
        
    JDK1.6.0_18
        Eclipse-3.6  Maven3.0.1  m2eclipse0.12.1.20110112-1712
        Tomcat6.0.10  maven-jetty-plugin6.1.26
        MySQL5.0.27  Navicat Lite for MySQL 8.1.20
        每個人的開發(fā)環(huán)境可能會有差異,但有一點(diǎn)我需要說明的是,JDK的版本不得低于1.5,因?yàn)橛玫搅撕芏?/span>1.5版才支持的新特性。TomcatJettyMavenMySQL不要低于我所用的版本,因?yàn)槲覜]在其它的版本上進(jìn)行測試。Navicat則是MySQL數(shù)據(jù)庫的圖形化操作工具。接下來我將介紹如何在Eclipse3.6中,使用m2eclipse插件構(gòu)建web應(yīng)用及測試開發(fā)環(huán)境。
        
    2、
    設(shè)置Maven
        Maven的安裝很簡單,只需要解壓即可,請設(shè)置PATH變量,這樣可以使用命令行進(jìn)行操作,然后就要在%MAVEN_HOME%\conf目錄下,對settings.xml作下修改
        
        這就是設(shè)置本地倉庫,目錄可以根據(jù)自己的實(shí)際情況更改,不過請使用"/"正斜杠,因?yàn)槲以趯?shí)際使用中,發(fā)現(xiàn)反斜杠有時候獲取不到資源。對于個人使用,設(shè)置好這個就OK了,至于Nexus配置不在本文討論范圍內(nèi),大家如有興趣可以去看看juven xu的博客,他是目前公認(rèn)的Maven專家。
        
    3、
    安裝m2eclipse
        選擇Help->Install New Software...在彈出的窗口中,點(diǎn)擊Add...又會彈出一個小窗口,輸入m2eclipse的安裝地址,如下圖所示:
        
        輸入完成后,點(diǎn)擊OK,這時Eclipse就開始查找這個插件了,請耐心等一會。
        
        插件找到后,請勾選要安裝的內(nèi)容,接下來就是一般的安裝流程了,此處省略500字。安裝完成請重新啟動Eclipse,然后再對這個插件進(jìn)行一番設(shè)置。
        
    4、
    設(shè)置m2eclipse
        進(jìn)入Perferences,選擇Maven,去掉Download repository index updates on startup前的勾,默認(rèn)情況是會在每次啟動Eclipse的時候自動去Maven中央倉庫下載索引,這無疑是非常不好的,要知道Maven中央倉庫所包含的jar資源非常龐大,而且每天都會有很多新的項(xiàng)目上傳,弄不好Eclipse還沒開始用,就被這些東西搞掛掉了。
        
        接下來選擇Installations將這個插件自帶的Maven換成之前安裝的Maven,這樣就保證了版本的一致性。
        
        設(shè)置好這個之后,再點(diǎn)擊User Settings,用本機(jī)mavensettings.xml替換默認(rèn)的配置文件,因?yàn)槟J(rèn)的設(shè)置是會將本地倉庫放到系統(tǒng)盤符\Documents and Settings\用戶目錄\.m2\repository這個目錄下面。
        
        大家可以看到,用maven中的配置文件替換后,下面的Local Repository自動變更為settings.xml中的設(shè)置。
        
    5、
    創(chuàng)建maven工程
        做完這些,我們就可以開始創(chuàng)建Maven工程了。選擇New->other...->Maven->Maven Project,然后選擇下一步
        
        請設(shè)置工作空間路徑,大象的默認(rèn)工作空間放在eclipse的根目錄下面,這里的Location顯示的應(yīng)該為空,為了進(jìn)行說明,特將路徑顯示出來。確定沒問題后,Next>
        
        這個列表顯示的就是maven支持的所有項(xiàng)目創(chuàng)建類型,我們是開發(fā)web應(yīng)用,所以請選擇maven-archetype-webapp
        
        最后一步輸入我們要創(chuàng)建的項(xiàng)目,在Maven世界中,使用坐標(biāo)來唯一標(biāo)識一個構(gòu)件,可以理解為項(xiàng)目,資源等等。Group Id表示當(dāng)前項(xiàng)目所屬的實(shí)際項(xiàng)目,Artifact Id定義實(shí)際項(xiàng)目中的一個Maven項(xiàng)目,根據(jù)名字就可以看出來,Group Id是一個大范圍,而Artifact Id是一個小范圍。比如大家都很熟悉的spring,就分成了spring-core.jarspring-beans.jarspring-context.jar等等。在maven里面,它的Group Id就是org.springframework,而Artifact Id則為spring-corespring-beansspring-context。怎么樣?理解了沒有?
        
        到此,項(xiàng)目生成了,請展開src/main,在main目錄下新建一個java文件夾,打開ssm3的項(xiàng)目屬性,選擇Java Build Path->Source->Add Folder...->勾選java,這樣做的目的,就是將src/main/java這個路徑作為源文件的文件夾,這和以往用MyEclipse做開發(fā)的目錄結(jié)構(gòu)是不同的。而maven的規(guī)則也是這樣定義的,假如你不進(jìn)行這個設(shè)置,就算你在main下面創(chuàng)建了java目錄,再添加包或類時,就會有問題,大家試試,看會出現(xiàn)什么錯誤。
        
        
    6、
    運(yùn)行ssm3
        接下來,在pom.xml里面加入maven-jetty-plugin插件,默認(rèn)生成的配置都可以去掉,整個pom就只有下圖所示的配置。
        
        打開Run Configurations,這有多種方式打開,可以從菜單Run里面選,也可以從工具欄選擇,還可以在項(xiàng)目點(diǎn)擊右鍵選擇。
        
        
        在彈出的窗口,Maven Build里面設(shè)置運(yùn)行參數(shù),點(diǎn)擊Browse Workspace...會彈出下圖那個小窗口,設(shè)定Base directory,加入jetty:run,點(diǎn)擊Run,啟動jetty
        
        在瀏覽器中輸入http://localhost:8080/ssm3會顯示Hello World!,調(diào)用的是ssm3/main/webapp/index.jsp,大象加了點(diǎn)內(nèi)容,結(jié)果就是這樣的
        
        到這里,關(guān)于在Eclipse里搭建maven環(huán)境,配置,創(chuàng)建,運(yùn)行,測試就全部講完了,大家動手做做,熟悉一下這種開發(fā)方式,接下來就會在這個骨架上開發(fā)SSM3示例。恩,我們下次繼續(xù)。
        本文為菠蘿大象原創(chuàng),如要轉(zhuǎn)載請注明出處。http://bolo.blogjava.net/
    posted on 2011-05-23 00:57 菠蘿大象 閱讀(29219) 評論(14)  編輯  收藏 所屬分類: Spring3

    評論:
    # re: Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解實(shí)例詳解(一) 2011-05-23 09:30 | roywong
    終于出來了終于出來了,期待已久。哈哈 感謝   回復(fù)  更多評論
      
    # re: Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解實(shí)例詳解(一) 2011-05-23 13:51 | QAlong
    問個問題,
    前幾天我也實(shí)踐了一個全注解的方式
    使用了mybatis-spring-integration,所有dao中的代碼都不需要使用實(shí)現(xiàn)類,而是直接接口對應(yīng)著mapping
    但是在實(shí)際中遇到批量操作數(shù)據(jù)的時候卻沒有很好的方式解決。
    所以請教一下有沒有好的建議  回復(fù)  更多評論
      
    # re: Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解實(shí)例詳解(一) 2011-05-23 14:14 | 菠蘿大象
    @QAlong
    你說的批量操作數(shù)據(jù)是什么意思?insert?update?delete?另外我感覺在mapping中定義namespace的方式,要創(chuàng)建好多個接口,維護(hù)起來不是很方便。  回復(fù)  更多評論
      
    # re: Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解實(shí)例詳解(一) 2011-05-23 17:58 | 目繪藝術(shù)
    您好!我看了你前面一篇關(guān)于eclipse與myeclipse的討論帖。
    不過我今天看你使用maven的方式全是圖形化界面。
    一種比較好的方式,使用命令行創(chuàng)建一個webapp項(xiàng)目。
    然后使用mvn eclipse:eclipse生成eclipse特性文件,很方便根本不需要你修改Java Build Path,麻煩。

    你寫的文章排版很不錯,看上去很舒心。圖片上面的水印是用什么工具做的?  回復(fù)  更多評論
      
    # re: Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解實(shí)例詳解(一) 2011-05-23 18:44 | 菠蘿大象
    @目繪藝術(shù)
    你說的在命令行操作是很好,不過要打出一長串命令,還有大小寫之分,對于初學(xué)者來說,不是很適合。水印是用輕松水印工具做的。  回復(fù)  更多評論
      
    # re: Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解實(shí)例詳解(一) 2011-05-26 00:39 | gavingeng
    呵呵,不錯!
    config的很基礎(chǔ)
    期待后續(xù)的更新......  回復(fù)  更多評論
      
    # re: Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解實(shí)例詳解(一) 2011-06-01 20:59 | QAlong
    @菠蘿大象
    我說的是batch操作,一次性插入成上千條數(shù)據(jù)的時候

    比如我是這樣實(shí)現(xiàn)的:
    public interface AreaDao {
    List<Area> getAll();
    void insert(Area area);
    void update(Area area);
    void delete(Area area);
    }

    public interface AreaManager {
    List<Area> getAll();
    String insert(Area area);
    void update(Area area);
    void delete(Area area);
    }

    @Service
    public class AreaManagerImpl implements AreaManager {
    @Autowired
    public AreaDao areaDao;
    public void setAreaDao(AreaDao areaDao) {
    this.areaDao = areaDao;
    }
    public List<Area> getAll() {
    return areaDao.getAll();
    }
    public String insert(Area area) {
    if (areaDao.getByArea(area).size() != 0)
    return "Error";
    areaDao.insert(area);
    return "Success";
    }
    public void update(Area area) {
    areaDao.update(area);
    }
    public void delete(Area area) {
    areaDao.delete(area);
    }
    }


    <mapper namespace="com.gc.dao.AreaDao">

    <resultMap id="RM.Area" type="com.gc.entity.Area">
    <result property="id" column="ID" />
    <result property="areaCode" column="AREA_CODE" />
    <result property="areaNameChn" column="AREA_NAME_CHN" />
    <result property="areaNameEng" column="AREA_NAME_ENG" />
    <result property="areaNameKrn" column="AREA_NAME_KRN" />
    <result property="isDeleted" column="IS_DELETED" />
    <result property="live" column="LIVE" />
    <collection property="parent" column="PARENT_ID" select="getParentArea" />
    </resultMap>

    <sql id="Area.columns">
    <![CDATA[
    ID,AREA_CODE,AREA_NAME_CHN,AREA_NAME_ENG,AREA_NAME_KRN,PARENT_ID,IS_DELETED
    ]]>
    </sql>

    <select id="getAll" resultMap="RM.Area">
    select * from bs_area where
    is_deleted=0
    </select>

    略。。。
    </mapper>








    <beans xmlns="http://www.springframework.org/schema/beans"" target="_new">http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"" target="_new">http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"" target="_new">http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"" target="_new">http://www.springframework.org/schema/jdbc"
    xmlns:context="http://www.springframework.org/schema/context"" target="_new">http://www.springframework.org/schema/context"
    xsi:schemaLocation="
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
    </bean>

    <!-- transaction manager, use JtaTransactionManager for global tx -->
    <bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
    </bean>
    <!-- enable component scanning (beware that this does not enable mapper
    scanning!) -->
    <context:component-scan base-package="com.gc.biz.impl" />
    <!-- enable autowire -->
    <context:annotation-config />

    <!-- enable transaction demarcation with annotations -->
    <tx:annotation-driven />

    <!-- scan for mappers and let them be autowired -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.gc.dao" />
    </bean>
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:mybatis-config.xml" />
    </bean>

    <!-- define the SqlSessionFactory, notice that configLocation is not needed
    when you use MapperFactoryBean
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    </bean>-->
    <bean id="expensesItemBatchDao" class="com.gc.dao.util.ExpensesItemBatchDao">
    <!-- <property name="jdbcTemplate" ref="jdbcTemplate"> </property> -->
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    </bean>
    </beans>

      回復(fù)  更多評論
      
    # re: Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解實(shí)例詳解(一) 2011-06-01 23:31 | 菠蘿大象
    @QAlong
    你的mapper文件里略去了insert方法的配置,我不知道你是怎么寫的,如果是一條普通的insert語句,從你的areaDao的插入方法可以看出,你傳入的參數(shù)是一個pojo對象,你想通過這樣一個對象來實(shí)現(xiàn)一次性插入成千上萬條數(shù)據(jù),我覺得這不可能。  回復(fù)  更多評論
      
    # re: Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解實(shí)例詳解(一) 2011-06-03 11:48 | 秦?zé)j
    "Group Id是一個大范圍,而Artifact Id是一個小范圍"根據(jù)spring實(shí)例講解 我更加深了印象。

    另外eclipse3.6 maven plugin安裝時候 可以從Help->Eclipse Marketplace->Search maven。 好處就是不用記那么多url了。  回復(fù)  更多評論
      
    # re: Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解實(shí)例詳解(一) 2012-05-23 23:08 | bj
    新建個maven project

    Select an Archetype 時候選擇了 maven-archetype-webapp

    finish的時候 提示我以下的錯誤

    Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:RELEASE from any of the configured repositories.  回復(fù)  更多評論
      
    # re: Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解實(shí)例詳解(一) 2012-05-24 10:33 | 菠蘿大象
    @bj
    你裝的插件是什么版本?你本地裝了maven嗎?不要用插件自帶的maven,down一個3.0的版本,按我寫的步驟做,是沒問題的  回復(fù)  更多評論
      
    # re: Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解實(shí)例詳解(一) 2012-05-27 11:01 | bj
    @菠蘿大象
    問題解決!謝謝大象!  回復(fù)  更多評論
      
    # re: Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解實(shí)例詳解(一)[未登錄] 2012-07-09 10:34 |
    @bj
    @bj
    你咋解決的?  回復(fù)  更多評論
      
    # re: Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解實(shí)例詳解(一) 2013-03-12 20:18 | 神一樣存在
    大象你好niubi  回復(fù)  更多評論
      
    主站蜘蛛池模板: 亚洲精品无码成人片在线观看| 33333在线亚洲| 四只虎免费永久观看| 成年人网站免费视频| 亚洲国产专区一区| 国产精品无码免费播放| 亚洲免费在线视频| 成人无码精品1区2区3区免费看| 亚洲精品无码专区| 亚洲国产系列一区二区三区| 久久精品国产亚洲av麻豆小说| 国产亚洲精品无码专区| 亚洲AV无码不卡在线观看下载| 特级做A爰片毛片免费69| 2015日韩永久免费视频播放| 丁香花在线视频观看免费| 2022免费国产精品福利在线| 免费精品视频在线| 麻豆91免费视频| 美女被羞羞网站免费下载| 老牛精品亚洲成av人片| 亚洲av日韩精品久久久久久a| 亚洲人成色7777在线观看| 亚洲男人第一无码aⅴ网站| 四虎影视永久免费视频观看| 日本大片在线看黄a∨免费| 在线观看人成视频免费| 免费无码又黄又爽又刺激| 免费一本色道久久一区| 成年美女黄网站色大免费视频| 免费精品人在线二线三线区别| 国产日本一线在线观看免费| 日本妇人成熟免费中文字幕| 韩国免费一级成人毛片| 搡女人免费视频大全| 永久免费bbbbbb视频| 国产成人免费a在线资源| 亚洲AV无码乱码在线观看性色扶| 亚洲国产精品视频| 久久夜色精品国产亚洲av| 亚洲国产精品一区第二页|