概述:
工作闲暇时间想要自己搭建一个web项目玩玩,没想到大半天才弄了一个springMVC+mybatis的网站,简直菜的不行,以下记录所有的步骤加深印象
使用环境
1.jdk1.8
2.maven 3.3.9
3.eclipse 4.6
4.tomcat 8.0
5.mysql
源码放在百度云
http://pan.baidu.com/s/1c5IlR4
简单说一下注意事项
1.jdk 注意配置环境变量,配置JAVA_HOME,path等,验证如下
2.maven配置环境变量,配置MAVEN_HOME,path等,验证如下
另:安装maven后修改conf文件夹的setting.xml
添加E:\Maven\Repositories设置本地Repositories的位置
profiles节点中加入
jdk18
true
1.8
1.8
1.8
1.8
3.eclipse离线加入maven插件
i.在eclipse目录下添加links和myplugins(随便命名)
ii.将插件解压到myplugins中(云盘有,或者网上下载)
iii.links下新建maven.link(随便命名) 内容:path=E:/IDE/eclipse/myplugins 对应上面myplugins的路径
项目构建
1.打开eclipse
i.File--》New—》other --》输入maven选择Maven Project—》next
ii.添加项目路径(我使用了默认)--》next
iii.输入webapp 创建一个web项目
iv.填写GroupId和Artifact Id,Pakage暂时不填—>finished
2.问题解决
创建项目后,报错如下
解决方案:
第一步:切换到navigator目录 修改以下两个文件夹信息
第二步:回到Project Explorer,右击项目—》build path --》Libraries目录—》Add Library—》Server Runtime --》选择一个tomcat 7、8都行 如果没有的话 需要在eclipse里面添加tomcat(install tomacat到tomcat的根目录)
第三步:Order and Export里面勾选tomcat--》apply
ok 问题解决 完成后文件结构如下:
2.配置文件
i.添加如下配置文件;每一行都以注释加以解释了,可下载源码来(也在云盘)
ii.添加jar包,使用maven添加,具体见pom.xml
iii.修改web.xml 默认使用servelet 2.3 改为3.1,加载配置文件,完整文件如下:
Archetype Created Web Application
contextConfigLocation
classpath:spring-mybatis.xml
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
true
encoding
UTF-8
encodingFilter
/*
org.springframework.web.context.ContextLoaderListener
org.springframework.web.util.IntrospectorCleanupListener
SpringMVC
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring-mvc.xml
1
true
SpringMVC
/
/index.jsp
3.MVC文件结构
不涉及配置,比较简单,一般项目为以上结构
4.JUnit测试
5.jsp测试
jsp如下
右击项目—》Run as—》Run on server –》tomcat 8.0
跳转如下
完成
下一步,将项目提交到github,并逐步完善