1、环境搭建
-
创建项目
-
创建模块,勾选webapp
-
配置pox文件
-
创建数据库
-
创建目录,java设置为root,并列resource设置为root
-
创建实体类,再main/java/com/hanchen/domain下
-
mapper接口
-
业务层service的接口与实现类
-
web层的控制类Controller
-
前端jsp页面
-
编写相应的配置文件,jdbc.xml && log4j && web.xml
-
具体的实现的配置文件[📎spring-mvc.xml]
-
账户mapper映射文件com.hanchen.mapper.AccountMapper.xml
-
mybatis的核心文件[📎sqlMapConfig-spring.xml]📎sqlMapConfig.xml]
2、具体配置
映射文件&核心文件
-
sqlMapConfig.xml中定义实体别名,
-
AccountMapper.xml书写相应的sql语句,
-
sqlMapConfig.xml配置相应jdbc工作环境,并加载jdbc的具体配置文件到该配置文件,
-
加载映射
spring和mvc配置文件
-
applicationContext.xml组件扫描mapper和service文件,将controller的扫描排除。
-
spring-mvc.xml组件扫描 主要扫描controller、配置mvc注解驱动、内部资源视图解析器、开发静态资源访问权限
web.xml内容填充
spring 监听器
springmvc的前端控制器
乱码过滤器
3、业务代码的编写
-
对controller层进行注释,并注释访问路径url
-
对service层进行注释
4、tomcat配置
一般创建项目就已经存在,只是有可能没有导入,需要手动的去导入一下
5、测试
将项目运行,发布到tomcat
出现的问题
java.io.FileNotFoundException: class path resource [spring/applicationContext.xml] cannot be opened because it does not exist
这个问题发生在配置文件的识别上,网页访问500
有两种可能性
1、配置文件路径错误
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
2、编译有问题(重点)
编译后的class文件必须要有以下的内容
即配置文件,如果没有,那么就是编译异常
需要在pom.xml文件中加入以下资源
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<filtering>false</filtering>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>