1. 工具准备
i)开发平台 Eclipse Java EE IDE Mars Release (4.5.0) + JDK 1.7 +
ii)项目管理工具 maven 3.3.3。 http://maven.apache.org/download.cgi
有了Maven,Spring、mybatis这些jar包都不用我们手动下载添加到项目的build path了,如果不熟悉的话可以参考http://blog.csdn.net/shymi1991/article/details/47255407
iii)Tomcat v7.0 http://tomcat.apache.org/
iv)数据库 MySQL 5.6 http://dev.mysql.com/downloads/mysql/
v)前端JS框架 AngularJS 1.3.9 https://angularjs.org/
vi)前端页面框架 Bootstrap 3 http://bootstrapuikit.com/
2. 配置eclipse,新建maven 项目
Tomcat设置环境变量,然后在eclipse的server中添加进来。
在Eclipse中安装m2e插件来集成maven。完成后重启Eclipse,File-->new-->Maven Project,选择maven-archetype-webapp。
输入包名Group ID:com.sommer.sample,项目名称Artifact ID: webproject。
新建号项目后index.jsp页面顶端会报错:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path。
是因为该JavaWeb工程类中没有添加Tomcat运行时相关类导致,在项目上右键-->Properties-->Java Build Path->Libraries--> Add Libray...-->Server Runtime -->Tomcat Server,完成后错误会自动消失。
这时候构建的目录是不完整的,我们要添加src\main\java源文件夹及需要的包名(可以直接在navigator视图下添加文件夹),具体项目目录结构如下:
3. 数据准备。在数据库中建立2个表:blog, author
create database sample; create table blog( id INT primary key auto_increment , title VARCHAR(100) not null, date DATE not null, author VARCHAR(20) not null, status VARCHAR(1) not null, category VARCHAR(10) not null, content TEXT); create table author( id INT primary key auto_increment, name VARCHAR(20) not null);
insert into blog values(1,"Java 集合","2014-11-17","Sommer","1","JAVA basic","some content"); insert into blog values(2,"Java 嵌套类(Nested Class):静态嵌套类,内部类,局部类,匿名类","2015-08-05","Sommer","1","JAVA basic","some content"); insert into blog values(3,"Java中的访问修饰符和修饰符","2015-08-05","Sommer","1","JAVA basic","some content"); insert into blog values(4,"用Eclipse创建第一个Spring项目(最最入门级)","2015-08-29","Sommer","1","JAVA spring","some content"); insert into blog values(5,"Spring 加载xml配置文件的方式 ApplicationContext","2015-08-30","Sommer","1","JAVA spring","some content"); insert into blog values(6,"Spring XML配置文件结构及bean的命名","2015-08-30","Winter","0","JAVA spring","some content"); insert into blog values(7,"项目管理工具maven使用示例","2015-08-30","Winter","1","project management","some content"); insert into blog values(8,"实例化Bean的方法(基于xml配置)","2015-09-01","Winter","1","JAVA spring","some content"); insert into blog values(9,"理解 Spring AOP的含义","2015-09-07","Winter","0","JAVA spring","some content"); insert into blog values(10,"Bean的两种依赖注入方式","2014-11-17","Winter","0","JAVA spring","some content"); insert into author values(1,"Sommer"); insert into author values(2,"Winter");