京山游俠

          專注技術,拒絕扯淡
          posts - 50, comments - 868, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          SpringSide 3.1.4.3是目前SpringSide的最新版本,也是完成度比較高的一個版本,用來做實際項目的開發(fā)應該絲毫不成問題。這里寫一下使用該版本開發(fā)一個簡單Web項目的全過程,當然,最重要的是我自己的一些心得體會。我的文章很長,只有耐下性子細看,才能體會個中三味。

          第一步、下載SpringSide 3.1.4.3 all-in-one版。這個過程太簡單了,SpringSide的官方網(wǎng)站是www.springside.org.cn,去那里就可以下載了,all-in-one版當然是懶人們的不二選擇。這里有一點很搞笑,該版本標的是SpringSide 3.1.4.3,但是下載后解壓縮,解壓縮出來的文件是springside-3.1.4.2,這可能是江南白衣的一點小小的失誤,據(jù)我猜測,3.1.4.3較3.1.4.1的進步應該是加入了jsp-api.jar這一個庫,希望白衣這次不要為了更改這個版本號上的失誤而再推出一個新版本,如果真要推出新版本,怎么樣也應該把我最近研究出來的多數(shù)據(jù)庫的配置加進去。

          第二步、安裝SpringSide。如果安裝過SpringSide以前的版本,最好把用戶目錄下的.m2文件夾刪掉,這個文件夾是Maven的本地倉庫所在地,雖說Maven可以有效保證庫文件不會發(fā)生版本沖突,但是刪除這個文件夾會使安裝過程加快,否則,SpringSide的安裝過程會不停詢問你是否覆蓋某某文件。刪除.m2文件夾后,運行springside-3.1.4.2目錄下的bin目錄中的quickstart.bat即可(前提條件是已經(jīng)安裝好了JDK5或以上版本,如果你的電腦中連JDK都沒有,就別來趟SpringSide的渾水了)。 等待這個文件運行完,就可以看到SpringSide 3提供的三個示例項目mini-web、mini-service、showcase都運行起來了,這時你可以細細體會一下SpringSide實現(xiàn)的各種特性。

          仔細察看SpringSide的bin目錄,發(fā)現(xiàn)該版本提供的腳本更加明確和有用,如start-db.bat可以用來啟動Derby數(shù)據(jù)庫,start-selenium.bat用來啟動selenium server,而start-tomcat.bat那就別說了,地球人都知道。

          如果要想使用SpringSide來生成項目,還有一點點小工作要做,就是把Maven的bin目錄加入到PATH環(huán)境變量中,如下圖:


          第三步,使用SpringSide生成項目。運行bin目錄下的new-project.bat即可,如下圖:


          在創(chuàng)建項目的過程中,該腳本會提出一些問題,其中groupId指的是你的組織的名稱,由于該項目由我私人貢獻,純屬示范用,所以我填了youxia.personal,因此,在第5個問題上,我選擇了personal.you作為我項目中的package的名字,這也是符合國際慣例的;artifactId指的是項目的名字,這里為MultiDatasourceExample,名字有點長,從名字就可以看出來我要示范多個數(shù)據(jù)源的配置。

          第四步、啟動Eclipse,導入項目。 生成的項目位于SpringSide目錄下的tools\generator\generated-project目錄下,下面是Eclipse的截圖:


          項目導入成功后,Eclispe資源管理器的截圖:

           可以看到,該項目一經(jīng)導入,立即可用,一個煩人的紅叉都沒有,這也正說明了該版本是SpringSide 3的一個革命性版本,從該版本開始,SpringSide 3的易用性提高了不止一個檔次。

          Eclipse推薦使用3.4及以上版本,因為在該版本中,對Tomcat服務器的管理更加方便,只需要在項目的快捷菜單中選擇Run On Server,即可自動打開Tomcat服務器并部署項目,如下圖:


          這里有一點一定要注意,由于SpringSide生成的項目默認使用的是Derby數(shù)據(jù)庫,所以要想成功運行項目,必須先啟動Derby數(shù)據(jù)庫,還記得前面提到的start-db.bat嗎?運行它!然后運行該項目的bin目錄下的init-db.jar,在數(shù)據(jù)庫中放入該項目的初始化數(shù)據(jù)。

          然后就可以點Run On Server來啟動項目了,讓大家見識一下Eclipse的嵌入式瀏覽器、Tomcat服務器視圖、Console視圖。真的是太方便了:


          第五步、將數(shù)據(jù)庫遷移到MySQL中。在項目中,創(chuàng)建數(shù)據(jù)庫和初始化數(shù)據(jù)庫的語句都是以SQL文件存在的,如下圖:


          但是該語句都是針對Derby的,如果要應用于MySQL,還必須得要做一些修改才行,先修改schema.sql,如下:

          drop table if exists RESOURCES_AUTHORITIES;
          drop table if exists ROLES_AUTHORITIES;
          drop table if exists USERS_ROLES;
          drop table if exists RESOURCES;
          drop table if exists AUTHORITIES;
          drop table if exists USERS;
          drop table if exists ROLES;

          create table USERS (
          ID 
          integer primary key auto_increment,
          LOGIN_NAME 
          varchar(20not null unique,
          PASSWORD 
          varchar(20),
          NAME 
          varchar(20),
          EMAIL 
          varchar(30)
          );

          create unique index USERS_LOGIN_NAME_INDEX on USERS(LOGIN_NAME);

          create table ROLES (
          ID 
          integer primary key auto_increment,
          NAME 
          varchar(20not null unique
          );

          create table USERS_ROLES (
          USER_ID integer not null,
          ROLE_ID 
          integer not null,
          FOREIGN KEY (ROLE_ID) references ROLES(ID),
          FOREIGN KEY (USER_IDreferences USERS(ID)
          );

          CREATE TABLE AUTHORITIES (
          ID 
          integer primary key auto_increment,
          NAME 
          varchar(20not null,
          DISPLAY_NAME 
          varchar(20not null
          );

          create table ROLES_AUTHORITIES (
          ROLE_ID 
          integer not null,
          AUTHORITY_ID 
          integer not null,
          FOREIGN KEY (ROLE_ID) references ROLES(ID),
          FOREIGN KEY (AUTHORITY_ID) references AUTHORITIES(ID)
          );

          CREATE TABLE RESOURCES (
          ID 
          integer primary key auto_increment,
          RESOURCE_TYPE 
          varchar(20not null,
          VALUE 
          varchar(255not null,
          ORDER_NUM 
          float not null
          );

          create table RESOURCES_AUTHORITIES (
          AUTHORITY_ID 
          integer not null,
          RESOURCE_ID 
          integer not null,
          FOREIGN KEY (AUTHORITY_ID) references AUTHORITIES(ID),
          FOREIGN KEY (RESOURCE_ID) references RESOURCES(ID)
          );

          該修改主要包含兩個地方,一個是在drop table后面加上了if exists,一個是把GENERATED ALWAYS as IDENTITY修改為auto_increment。而load-data.sql不需要修改。

          然后,啟動MySQL,在MySQL中使用上面的兩個sql文件創(chuàng)建數(shù)據(jù)庫和添加初始化數(shù)據(jù),如下圖:


          然后更改數(shù)據(jù)庫連接,修改項目的application.properties文件,如下:
          #jdbc settings
          jdbc.url
          =jdbc:mysql://localhost:3306/MultiDatasourceExample?useUnicode=true&characterEncoding=utf8
          jdbc.username
          =youxia
          jdbc.password
          =******

          #hibernate settings
          hibernate.show_sql
          =false
          hibernate.format_sql
          =false
          hibernate.ehcache_config_file
          =/ehcache/ehcache-hibernate-local.xml

          修改項目的applicationContext.xml文件,這里要修改兩個地方,一個為DriverClassName,一個為hibernate.dilect,如下:
          <?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:jee
          ="http://www.springframework.org/schema/jee" 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-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
              default-lazy-init
          ="true">

              
          <description>Spring公共配置文件 </description>

              
          <!-- 定義受環(huán)境影響易變的變量 -->
              
          <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                  
          <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
                  
          <property name="ignoreResourceNotFound" value="true" />
                  
          <property name="locations">
                      
          <list>
                          
          <!-- 標準配置 -->
                          
          <value>classpath*:/application.properties</value>
                          
          <!-- 本地開發(fā)環(huán)境配置 -->
                          
          <value>classpath*:/application.local.properties</value>
                          
          <!-- 服務器生產(chǎn)環(huán)境配置 -->
                          
          <!-- <value>file:/var/myapp/application.server.properties</value> -->
                      
          </list>
                  
          </property>
              
          </bean>

              
          <!-- 使用annotation 自動注冊bean,并保證@Required,@Autowired的屬性被注入 -->
              
          <context:component-scan base-package="personal.youxia" />

              
          <!-- 數(shù)據(jù)源配置,使用應用內(nèi)的DBCP數(shù)據(jù)庫連接池 -->
              
          <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
                  
          <!-- Connection Info -->
                  
          <property name="driverClassName" value="com.mysql.jdbc.Driver" />
                  
          <property name="url" value="${jdbc.url}" />
                  
          <property name="username" value="${jdbc.username}" />
                  
          <property name="password" value="${jdbc.password}" />

                  
          <!-- Connection Pooling Info -->
                  
          <property name="initialSize" value="5" />
                  
          <property name="maxActive" value="100" />
                  
          <property name="maxIdle" value="30" />
                  
          <property name="maxWait" value="1000" />
                  
          <property name="poolPreparedStatements" value="true" />
                  
          <property name="defaultAutoCommit" value="false" />
              
          </bean>

              
          <!-- 數(shù)據(jù)源配置,使用應用服務器的數(shù)據(jù)庫連接池 -->
              
          <!--<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/ExampleDB" />-->

              
          <!-- Hibernate配置 -->
              
          <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
                  
          <property name="dataSource" ref="dataSource" />
                  
          <property name="namingStrategy">
                      
          <bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
                  
          </property>
                  
          <property name="hibernateProperties">
                      
          <props>
                          
          <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
                          
          <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                          
          <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
                          
          <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider
                          
          </prop>
                          
          <prop key="hibernate.cache.provider_configuration_file_resource_path">${hibernate.ehcache_config_file}</prop>
                      
          </props>
                  
          </property>
                  
          <property name="packagesToScan" value="personal.youxia.entity.*" />
              
          </bean>

              
          <!-- 事務管理器配置,單數(shù)據(jù)源事務 -->
              
          <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
                  
          <property name="sessionFactory" ref="sessionFactory" />
              
          </bean>

              
          <!-- 事務管理器配置,多數(shù)據(jù)源JTA事務-->
              
          <!--
                  <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager or
                  WebLogicJtaTransactionManager" />
              
          -->

              
          <!-- 使用annotation定義事務 -->
              
          <tx:annotation-driven transaction-manager="transactionManager" />
          </beans>

          由于SpringSide不提供Mysql的jdbc驅(qū)動,所以需要自己去MySQL的官方網(wǎng)站下載,將下載到的mysql-connector-5.*.jar復制到項目的WEB-INF中的lib目錄中。然后運行項目,成功。至此,成功將項目遷移到MySQL中。

          第六步、添加數(shù)據(jù)表、編寫Entity類、編寫Dao類、Manager類,并進行單元測試。還是以前幾篇文章中提到的文章發(fā)布系統(tǒng)為例,每一篇文章對應多篇評論,所以說據(jù)庫中需創(chuàng)建articles和comments兩個數(shù)據(jù)表,如下:
          create   table  articles(
          id  
          int   primary   key  auto_increment,
          subject  
          varchar ( 20 )  not   null ,
          content  
          text );

          create   table  comments(
          id  
          int   primary   key  auto_increment,
          content  
          varchar ( 255 ),
          article_id  
          int   not   null ,
          foreign   key  (article_id)  references  articles(id)
          );


          在編寫Java代碼之前,我還要做一點小工作,什么工作呢?那就是要為我自己的項目創(chuàng)建一個單獨的源文件夾,因為src\main\java這個文件夾已經(jīng)被江南白衣放入了太多的package,而且因為涉及到security,所以層次也不明顯,操作起來不方便,找起代碼來也不夠快。下面是我創(chuàng)建了自己的源文件夾后的截圖:

          在我自己的源文件夾中,只創(chuàng)建了四個package,剛好代表從底到上的四個層次,這樣,找起代碼來要方便得多。

          先來Entity層,Article.java的代碼如下:

          package personal.youxia.entity;

          import java.util.LinkedHashSet;
          import java.util.Set;

          import javax.persistence.CascadeType;
          import javax.persistence.Entity;
          import javax.persistence.JoinColumn;
          import javax.persistence.OneToMany;
          import javax.persistence.OrderBy;
          import javax.persistence.Table;

          import org.hibernate.annotations.Cache;
          import org.hibernate.annotations.CacheConcurrencyStrategy;
          import org.hibernate.annotations.Fetch;
          import org.hibernate.annotations.FetchMode;

          @Entity
          // 表名與類名不相同時重新定義表名.
          @Table(name = "articles")
          // 默認的緩存策略.
          @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
          public class Article extends IdEntity {
              
          private String subject;
              
          private String content;
              
          private Set<Comment> comments = new LinkedHashSet<Comment>();

              
          public String getSubject() {
                  
          return subject;
              }


              
          public void setSubject(String subject) {
                  
          this.subject = subject;
              }


              
          public String getContent() {
                  
          return content;
              }


              
          public void setContent(String content) {
                  
          this.content = content;
              }


              @OneToMany(cascade 
          = { CascadeType.ALL })
              @JoinColumn(name 
          = "article_id")
              
          // Fecth策略定義
              @Fetch(FetchMode.SUBSELECT)
              
          // 集合按id排序.
              @OrderBy("id")
              
          // 集合中對象id的緩存.
              @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
              
          public Set<Comment> getComments() {
                  
          return comments;
              }


              
          public void setComments(Set<Comment> comments) {
                  
          this.comments = comments;
              }

          }

          Comment.java如下:
          package personal.youxia.entity.entities;

          import javax.persistence.Column;
          import javax.persistence.Entity;
          import javax.persistence.Table;

          import org.hibernate.annotations.Cache;
          import org.hibernate.annotations.CacheConcurrencyStrategy;

          import personal.youxia.entity.IdEntity;

          @Entity
          // 表名與類名不相同時重新定義表名.
          @Table(name = "comments")
          // 默認的緩存策略.
          @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
          public class Comment extends IdEntity {
              
          private String content;
              
          private Long articleId;

              
          public String getContent() {
                  
          return content;
              }

              
          public void setContent(String content) {
                  
          this.content = content;
              }
              
              @Column(name 
          = "article_id")
              
          public Long getArticleId() {
                  
          return articleId;
              }

              
          public void setArticleId(Long articleId) {
                  
          this.articleId = articleId;
              }
          }

          編寫Dao層代碼,ArticleDao.java如下:
          package personal.youxia.dao;

          import org.springside.modules.orm.hibernate.HibernateDao;

          import personal.youxia.entity.Article;

          public class ArticleDao extends HibernateDao<Article, Long> {

          }

          CommentDao.java如下:
          package personal.youxia.dao;

          import org.springside.modules.orm.hibernate.HibernateDao;

          import personal.youxia.entity.Comment;

          public class CommentDao extends HibernateDao<Comment, Long> {

          }

          可以看出,以上代碼都從HibernateDao繼承,得益于泛型支持,基本不需要編寫一行代碼。

          編寫B(tài)ussiness層代碼,這一層,白衣使用的包名為service,而類名的后綴都是Manager,我就跟他學算了,懶得改了。
          ArticleManager.java如下:
          package personal.youxia.service;

          import org.springframework.beans.factory.annotation.Autowired;
          import org.springside.modules.orm.hibernate.HibernateDao;

          import personal.youxia.dao.ArticleDao;
          import personal.youxia.entity.Article;

          public class ArticleManager extends EntityManager<Article, Long> {
              @Autowired
              
          private ArticleDao articleDao;

              
          public void setArticleDao(ArticleDao articleDao) {
                  
          this.articleDao = articleDao;
              }


              @Override
              
          protected HibernateDao<Article, Long> getEntityDao() {
                  
          // TODO Auto-generated method stub
                  return articleDao;
              }


          }

          CommentManager.java如下:
          package personal.youxia.service;

          import org.springframework.beans.factory.annotation.Autowired;
          import org.springside.modules.orm.hibernate.HibernateDao;

          import personal.youxia.dao.CommentDao;
          import personal.youxia.entity.Comment;

          public class CommentManager extends EntityManager<Comment, Long> {
              @Autowired
              
          private CommentDao commentDao;

              
          public void setCommentDao(CommentDao commentDao) {
                  
          this.commentDao = commentDao;
              }


              @Override
              
          protected HibernateDao<Comment, Long> getEntityDao() {
                  
          // TODO Auto-generated method stub
                  return commentDao;
              }


          }

          以上代碼大同小異,都是從EntityManager繼承,并使用Spring的IoC特性,將Dao類注入到Manager類之中,并重載getEntityDao方法來使用該注入的Dao。這個時候,為了驗證這些數(shù)據(jù)訪問相關的層能否正常運行,可以編寫單元測試。 代碼如下:
          package personal.youxia.test;

          import org.junit.Test;
          import org.springframework.beans.factory.annotation.Autowired;
          import org.springside.modules.test.junit4.SpringTxTestCase;

          import personal.youxia.entity.entities.Article;
          import personal.youxia.entity.entities.Comment;
          import personal.youxia.service.ArticleManager;
          import personal.youxia.service.CommentManager;

          public class DataAccessTest extends SpringTxTestCase {
              @Autowired
              
          private ArticleManager articleManager;
              @Autowired
              
          private CommentManager commentManager;

              
          public void setArticleManager(ArticleManager articleManager) {
                  
          this.articleManager = articleManager;
              }


              @Test
              
          public void addArticle() {
                  Comment comment 
          = new Comment();
                  Article article 
          = new Article();
                  article.setSubject(
          "test");
                  article.setContent(
          "test");
                  articleManager.save(article);
                  comment.setArticleId(article.getId());
                  commentManager.save(comment);
              }

          }

          單元測試一運行,發(fā)現(xiàn)了三個問題,先是出現(xiàn)Manager類沒有注入成功的錯誤,經(jīng)檢查發(fā)現(xiàn)所有的Manager類都應該使用@Service注解,再出現(xiàn)的錯誤是提示Dao類沒有注入成功,經(jīng)檢查發(fā)現(xiàn)所有的Dao類須使用@Repository注解,最后出現(xiàn)的錯誤是找不到Entity類的錯誤,經(jīng)檢查發(fā)現(xiàn)Entity類不能位于personal.youxia.entity包中,必須位于其子包中,這是由applicationContext.xml文件中的配置決定的,更改包名為personal.youxia.entity.entities后,問題解決。

          下一步就應該是編寫Action和JSP了,由于文章太長,在Blogjava的編輯器中編輯已經(jīng)非常緩慢了,所以只有將該文章分為上中下三部分。且看下回分解!

          使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(中)

          評論

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-07-19 23:25 by MxdStudio
          期待京山游俠前輩的下一篇文章,最近公司調(diào)研SpringSide,無奈很多地方摸不著頭緒,看完此文開朗了許多

          希望能盡早看到中篇和下篇 支持

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)[未登錄]  回復  更多評論   

          2009-07-19 23:30 by john
          DataAccessTest 中的測試 addArticle有回滾嗎?
          我運行mini-web的UserManagerTest.crudUser方法,并不會回滾事物無效。在執(zhí)行userManager.save方法,數(shù)據(jù)庫立即保存到數(shù)據(jù)庫

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-07-20 20:29 by 12530彩鈴
          數(shù)據(jù)庫立即保存到數(shù)據(jù)庫

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-07-21 10:24 by sunning
          我的運行addArticle 會出現(xiàn)這個錯誤,是什么原因呢
          org.hibernate.exception.GenericJDBCException: could not insert: [personal.sunning.entity.security.Comment]
          at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
          at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
          at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64)
          at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2176)
          at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2656)
          at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
          at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
          at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-07-21 16:20 by 虎嘯龍吟
          不錯的入門文章。只是現(xiàn)在已不用EntityManager<T t, Long id>了。

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-07-21 17:52 by 海邊沫沫
          @john
          @12530彩鈴
          我確定數(shù)據(jù)不會保存到數(shù)據(jù)庫,事務是絕對會回滾的,經(jīng)過我多次測試沒有錯,請你們確認一下是不是從SpringTxTestCase繼承的,另外,MySQL只有InnoDB引擎支持事務,MyISAM引擎是不支持事務的。

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-07-21 17:52 by 海邊沫沫
          @sunning
          你用ArticleDao保存Comment?

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-07-21 17:55 by 海邊沫沫
          @虎嘯龍吟
          不用EntityManager用什么呢?江南白衣的示例中都大量應用這個基類啊。
          雖然文檔中說可以省略掉一層,但是實際情況中最好不要省略,因為@Transactional注解要在這一層使用。

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)[未登錄]  回復  更多評論   

          2009-07-22 20:50 by john
          @海邊沫沫
          謝謝,就是引擎的問題。

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-07-23 10:58 by MxdStudio
          請問Enitiy Comment中是不是缺少了setArticleId(long articleId)方法?

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-07-23 20:02 by 海邊沫沫
          @MxdStudio
          沒有缺,在它的基類IdEntity中。

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-07-23 23:08 by zhj
          @海邊沫沫
          他基類IdEntity里沒有Long articleId屬性。。。。

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-07-25 12:39 by 海邊沫沫
          @MxdStudio
          是我回復錯誤,我貼的代碼中確實少了setArticleId屬性。但是提供下載的源代碼里面有。
          我馬上修改我文章中的錯誤

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-07-25 18:38 by dbclick
          如果主鍵不是auto_increment應該怎么辦?

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)[未登錄]  回復  更多評論   

          2009-07-25 20:25 by 海邊沫沫
          @dbclick
          這確實是個問題,我不知道別的數(shù)據(jù)庫應該怎么辦,因為我只會MySQL和MS SQL Server。
          在以前的一個項目中,確實有的表有ID列,但是不需要它自動增長,這時候,只需要用@Id注解即可,程序代碼中就需要先自己設置Id,然后保存到數(shù)據(jù)庫中。

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-08-10 17:40 by 藝凡♂
          3.1.5中的EntityManager沒了,應該怎么辦啊?

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-08-10 21:48 by 海邊沫沫
          白衣更新真的很快,我剛下在了3.1.5的代碼研究了一下。其實沒有EntityManager也沒有關系,自己寫Mananger類也比較簡單,記得使用@Service注解和@Transactional注解就可以了,而且Manager類也不用依賴哪一個Entity了,一個Manager可以使用任意多個Entity,只要使用@Autoware注入即可。

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-08-17 22:09 by 藝凡♂
          Comment里的屬性為什么是articleId,而不是article對象呢?

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-08-18 17:14 by 海邊沫沫
          因為我使用的是最簡單的一對多關系,是單向的關系。

          而SpringSide的示例代碼大量使用的是多對多關系,是雙向的關系。如果你要把我的代碼中改成雙向的關系也是沒有問題的,用注解配置起來也比較方便。

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-10-08 09:40 by mcdull
          博主有沒有遇到springside在搜索框輸入中文會出現(xiàn)亂碼的情況啊?怎么解決呢?謝謝。

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-10-19 21:10 by yangjiandong
          現(xiàn)在3.1.8版上不采用EntityService了。

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2009-12-02 18:46 by mefly
          亂碼問題可以改tomcat ,我也有過相同經(jīng)歷
          http://forum.springside.org.cn/viewthread.php?tid=3757

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2011-02-18 14:04 by 哎 春天
          你的代碼是手寫的還是自動生成的呢?

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2012-02-14 09:39 by 程序員之家
          好問看看啊

          # re: 使用SpringSide 3.1.4.3開發(fā)Web項目的全過程(上)  回復  更多評論   

          2014-04-19 12:03 by 最代碼
          最代碼轉(zhuǎn)載地址:http://www.zuidaima.com/share/1781596496120832.htm
          主站蜘蛛池模板: 安庆市| 新野县| 南郑县| 扶风县| 军事| 岐山县| 泰来县| 莱州市| 濮阳县| 临澧县| 伊通| 霍城县| 石台县| 绍兴县| 乐昌市| 兴安县| 措美县| 大新县| 芦山县| 昌邑市| 屯留县| 临洮县| 饶平县| 高淳县| 萨嘎县| 高安市| 舟曲县| 宜城市| 连山| 柘荣县| 昌吉市| 巴林右旗| 云林县| 隆回县| 遵义县| 思茅市| 嘉峪关市| 平定县| 武川县| 马鞍山市| 砀山县|