http://blog.csdn.net/u011403655/article/details/46843331
File-New Project
选中左侧的Maven,选中右侧上方的Create from archetype,然后选中下方列表中的webapp,然后点击Next
在GroupId和ArtifactId中填入指定内容,点击Next
直接点Next
输入项目名称,Finish
Idea会自动开始下载所依赖的包,等待其完成。
项目刚建好的时候是没有这些文件的,所以自己手动创建缺少的文件夹(包)
创建完后的项目框架:
依赖包需要如下:
spring framework aspectj事务 c3p0数据源 servlet/jsp api junit4 mybatis mybatis spring整合 mysql driver
jstl
[html] view plain copy
插件需要用到mybatis的逆向工程
完整的pom.xml代码清单:
user表结构
[sql] view plain copy
在main/resources中创建generatorConfig.xml文件
generatorConfig.xml代码清单
[html] view plain copy
点击idea右侧的maven选项卡,选择其中的mybatis-generator,点击顶部的绿色按钮运行
如果没有出错的话,应该会自动生成mapper接口文件、xml文件、pojo文件。
在resources/config中创建db.properties,该文件用来描述mysql连接信息
[plain] view plain copy
在resources/config/mybatis中创建SqlMapConfig.xml文件,该文件为Mybatis的配置文件,由于跟spring整合,所以一些基础配置文件都在spring中,在这里该文件中值需要写文件的框架
[html] view plain copy
在resources/config/spring中创建springmvc.xml文件
[html] view plain copy
在resources/config/spring中创建applicationContext-dao.xml、application-service.xml、applicationContext-transaction.xml文件
applicationContext-dao.xml
[html] view plain copy
application-service.xml
[html] view plain copy
applicationContext-transaction.xml
[html] view plain copy
修改web.xml文件内容
[html] view plain copy
创建一个简单的service,只有一个查看所有用户列表的功能
UserService.java
[java] view plain copy
实现类UserServiceImpl.java
[java] view plain copy
[java] view plain copy
根据之前写的controller,返回的视图为findUser,所以在/WEB-INF/views中创建findUser.jsp文件,用来显示查询出来的结果
[html] view plain copy
版权声明:原创文章转载请注明原始出处,违者必究。