springside作為一款國內優秀javaEE開源項目,是JavaEE世界中的主流技術選型,最佳實踐的總結與演示。
最近心血來潮自己用springside生成一個項目,感覺十分方便,推薦給大家。
一、技術選型
** ** 項目框架:spring+springMVC+Mybatis+mysql
管理工具:maven
開發工具:intellij idea
二、搭建步驟
1、首先在GitHub上下載springside的開源包,下載地址:https://github.com/seightday/springside4-4.2.3.GA-fork
2、下載之后,解壓進入support/maven-archetype目錄下,執行install
3、自動生成項目
雙擊根目錄中的generate-project.bat,假如報如下錯誤,(org.springside.examples:quickstart-archetype:4.2.3.GA)
則用Nodepad++打開generate-project,修改版本為4.2.2.GA
然后在執行generate-project,出現交互提示,輸入你想創建的項目信息,確認后生成項目
生成項目在:\springside4-4.2.3.GA-fork-master\generated-projects目錄下
三、將項目導入intellij idea中
1、打開idea,open選擇項目目錄
2、intellij idea會自動下載依賴包, 在pom.xml的bulid中,引入tomcat
<!-- tomcat7 插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<port>8080</port>
<path>/bwrp</path>
<uriEncoding>UTF-8</uriEncoding>
<finalName>bwrp</finalName>
<server>tomcat7</server>
</configuration>
</plugin>
然后執行tomcat:run命令就可以跑起來
終于我們的項目終于跑起來了
四、集成mybatis
1、在pom中引入mybatis依賴包
<!-- mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.7</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
2、修改applicationContext,添加mybatis配置內容
<!--MyBatis配置-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自動掃描entity目錄, 省掉Configuration.xml里的手工配置 -->
<property name="typeAliasesPackage" value="com.dzdc.entity" />
<!-- 顯式指定Mapper文件位置 -->
<property name="mapperLocations" value="classpath:/mybatis/*Mapper.xml" />
</bean>
<!-- 掃描basePackage下所有以@MyBatisRepository標識的 接口-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.dzdc" />
<property name="annotationClass" value="com.mytest.iqes.repository.Mybatis.MyBatisRepository"/>
</bean>
MyBatisRepository類代碼如下:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Component
public @interface MyBatisRepository {
String value() default "";
}
3、修改application.properties
4、修改pom中醒目屬性
5、再次啟動項目