ssm基于注解的框架搭建

                                                                                                             SSM框架的搭建---基础篇

思路:首先我们需要搭建的就是Spring的开发环境,只有学到开发的都知道Spring是轻量级的框架,他可以进行bean的管理和IOC注入等的操作。那么我们第一步就进行spring的搭建。然后进行一步步的整合springmvc和mybatis

1、首先新建项目。。。。这点应该都不需要说了。然后将SSM框架的一些jar包导进去,注意版本的问题。

以上是我的一些的jar包。

2、进行在web.xml的配置

(1)先进行配置spring的文件,其中contextConfigLocation是固定的,param-value是根据你本人建立的路径,我的是直接的建在src下的,当然你的可以放在包里,那么路径对应的也需要改变

(2)项目中会有乱码什么的出现,那么我们也进行对应的配置优化、使用的原理是filter拦截器

(3)进行配置搭建springmvc的配置

3、下面对数据库(db)的资料进行组织数据

(1)针对oracle数据库的

(2)针对MySQL数据库的

4、进行真正的配置Spring文件,因为我当时在web.xml中写的是spring.xml名字,所以在src下新建一个Spring.xml的文件。这里进行控制数据库、控制bean、控制mybatis等。。。。

(1)首先需要引入约束

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  http://www.springframework.org/schema/mvc
  http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-3.2.xsd
  http://www.springframework.org/schema/aop
  http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
  http://www.springframework.org/schema/tx
  http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">
  </beans>

上面是我组织的一些约束、、、、、网上好多的,都可以找一下

(2)

5、进行配置springmvc的一些信息,只要是为了配置视图映射、处理器映射器、处理器解析器。。。等

上面的约束的引入,跟Spring是一样的,我这里就不粘贴了。。。。

6、进行配置mybatis的文件

(1)主文件的配置

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

</configuration>

以上是对应的约束(2)对应的 每一个实体类都会对应一个mapper.xml,比如,我的类名为MyUser,那么对应的xml为MyUserMapper.xml

7、进行测试搭建系统的一些步骤

(1)以下是我进行搭建的一些目录。。。可以参考,但是搭建的时候根据之前配置文件中的扫描的包名称都是需要改变的,这个按照你自己的习惯来

(2)进行编写javabean类  MyUser

(3)那我们接下来继续先写UserDao的类

(4)service层面的接口

(5)serviceImpl的编写是重要的

(5)对usercontroller的编写

8、进行写.jsp并且进行测试了。。。

(1)写登录页面,,,,

其中index.jsp是在webroot下的一个jsp文件夹下创建的。。。。

(2)返回的页面。success.jsp是直接的建立在webroot下面的

9、进行测试。。。。。

将项目加到Tomcat中,并且进行启动,,,也许因为你自己的马虎,有可能不能直接的启动,,,那你自己找原因吧,或者进行留言,这也是鄙人写的第一篇文章,也许有不足之处还望见谅并且尽情指出错误指出

进行测试,我的index因为在jsp文件夹下,所以我的测试网址是

(1)进行输入用户名密码,当密码和用户不对应时,

(2)当用户名和密码对应时、、、

10.那么对应数据库的建立,我这里是用的oracle,那么需要进行建立一个用户和密码都为ssm的一个用户,并且分配对应的权限,并且进行新建一个MyUser的表,并且进行插入两条数据

实际如下

-- Create table
create table MYUSER
(
  id       VARCHAR2(32) not null,
  username VARCHAR2(50),
  password VARCHAR2(32)
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
-- Add comments to the table
comment on table MYUSER
  is 'myUser';
-- Add comments to the columns
comment on column MYUSER.id
  is 'id';
comment on column MYUSER.username
  is '用户名';
comment on column MYUSER.password
  is 'mima';




最后我也将自己搭建的项目上传到我的博客用户中,希望你们可以查看,,,谢谢了





猜你喜欢

转载自blog.csdn.net/zhoudado921/article/details/78122838