Maven+SpringMVC+myBatis项目搭建(MyEclipse)
Maven+SpringMVC+myBatis项目搭建(MyEclipse)
- Maven项目搭建
- SpringMVC+MyBatis项目搭建
Maven项目搭建
在Myeclipse中,新建maven projectàweb的项目要选webapp如图à填写信息后fin
(注意:此时maven仓库连全球仓库,点击next后要下载webapp包,箭头处会出现进度条,如没有下载后面创建maven项目会报错)
即maven-web项目新建完成!
新建完成后项目只有src/main/resources目录,如想添加目录如图添加新目录
在pom.xml中Maven导入SpringMVC+MyBatis依赖包清单
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
后续步骤如“Spring+MyBatis项目搭建”第3步以后
*如果不构建maven项目则直接执行“Spring+MyBatis项目搭建”步骤即可
SpringMVC+MyBatis项目搭建
1. 新建一个Web项目
2. 在lib下,添加Spring和myBatis的依赖包
3. 新建applicationContext.xml文件
<?xml version="1.0" encoding="UTF-8"?> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-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/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-2.5.xsd">
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
id="pointcut" />
|
4. 新建springmvc.xml
<?xml version="1.0" encoding="UTF-8"?> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
|
5. 新建database.properties文件
# my DB supp.driverClassName=com.mysql.jdbc.Driver supp.url=jdbc\:mysql\://127.0.0.1\:3306/test?allowMultiQueries\=true&useUnicode=true&characterEncoding=UTF-8 supp.username=root supp.password=123456 |
6. 修改web.xml文件
<?xml version="1.0" encoding="UTF-8"?> xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
|
7. 完成项目中java类的搭建
*注意标签的使用