博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring整合ssmXML版
阅读量:5821 次
发布时间:2019-06-18

本文共 6602 字,大约阅读时间需要 22 分钟。

以下是一个简单的ssm项目:如果中途报错,肯定是tomcat配置或者数据库配置有问题,在程序中注意将包名等配置换成自己的。数据库表需要提前建好,并加入数据,注意表结构要和实体对象对应。

1.开发条件:eclipse + comcat7.0

2.创建一个Dynamic Web Project项目,大概的目录结构。

3.jar包如下:

aopalliance.jar

asm-3.3.1.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
aspectjweaver.jar
cglib-2.2.2.jar
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
freemarker-2.3.19.jar
javassist-3.17.1-GA.jar
jstl-1.2.jar
log4j-1.2.17.jar
log4j-api-2.0-rc1.jar
log4j-core-2.0-rc1.jar
mybatis-3.2.7.jar
mybatis-spring-1.2.3.jar
mysql-connector-java-5.1.20-bin.jar
ognl-3.0.5.jar
slf4j-api-1.7.5.jar
slf4j-log4j12-1.7.5.jar
spring-aop-4.1.6.RELEASE.jar
spring-aspects-4.1.6.RELEASE.jar
spring-beans-4.1.6.RELEASE.jar
spring-context-4.1.6.RELEASE.jar
spring-context-support-4.1.6.RELEASE.jar
spring-core-4.1.6.RELEASE.jar
spring-expression-4.1.6.RELEASE.jar
spring-jdbc-4.1.6.RELEASE.jar
spring-orm-4.1.6.RELEASE.jar
spring-tx-4.1.6.RELEASE.jar
spring-web-4.1.6.RELEASE.jar
spring-webmvc-4.1.6.RELEASE.jar
standard-1.1.2.jar
struts2-core-2.3.4.jar
struts2-spring-plugin-2.3.4.jar

xwork-core-2.3.4.jar

4.页面访问结果:http://localhost:8080/spring001/list.action

 

下面开始上代码:

1.UserDao

package cn.mr.li.dao;import java.util.List;import cn.mr.li.entity.User;public interface UserDao {    List
getUser();}

2.UserDaoImpl

package cn.mr.li.dao.impl;import java.util.List;import org.mybatis.spring.support.SqlSessionDaoSupport;import cn.mr.li.dao.UserDao;import cn.mr.li.entity.User;public class UserDaoImpl extends SqlSessionDaoSupport implements UserDao {        @Override    public List
getUser() { return this.getSqlSession().selectList("cn.mr.li.entity.user.mapper.getAll"); }}

3.userService

package cn.mr.li.service;import java.util.List;import cn.mr.li.entity.User;public interface UserService {    List
getAll();}

4.userServiceImpl

package cn.mr.li.service.impl;import java.util.List;import cn.mr.li.dao.UserDao;import cn.mr.li.entity.User;import cn.mr.li.service.UserService;public class UserServiceImpl implements UserService {    private UserDao userDao;        @Override    public List
getAll() { return userDao.getUser(); } public UserDao getUserDao() { return userDao; } public void setUserDao(UserDao userDao) { this.userDao = userDao; }}

5.user

package cn.mr.li.entity;public class User {    private int id;        private String name;        private int age;    public int getId() {        return id;    }    public void setId(int id) {        this.id = id;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public int getAge() {        return age;    }    public void setAge(int age) {        this.age = age;    }    public User(int id, String name, int age) {        super();        this.id = id;        this.name = name;        this.age = age;    }        public User() {    }}

6.user-mapper.xml

7.UserAction

package cn.mr.li.action;import java.util.List;import cn.mr.li.entity.User;import cn.mr.li.service.UserService;public class UserAction {    private List
list; private UserService userService; public String list(){ list = userService.getAll(); return "success"; } public List
getList() { return list; } public void setList(List
list) { this.list = list; } public UserService getUserService() { return userService; } public void setUserService(UserService userService) { this.userService = userService; }}

8.config.spring  user.xml

9.config.struts  user.xml

/list.jsp

10applicationContext.xml

11.mybatis-cfg.xml

12.struts.xml

13.web.xml

contextConfigLocation
classpath:applicationContext.xml
org.springframework.web.context.ContextLoaderListener
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
*.action
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp

14.index.jsp,好像没用到

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>              My JSP 'index.jsp' starting page    
This is my JSP page.

15.list.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>              My JSP 'index.jsp' starting page    
编号 姓名 密码
${bean.id } ${bean.name } ${bean.age }

 

转载于:https://www.cnblogs.com/li-yan-long/p/10670042.html

你可能感兴趣的文章
php生成word,并下载
查看>>
python 函数参数
查看>>
紫书 习题8-11 UVa 1615 (区间选点问题)
查看>>
asp.net mvc学习(Vs技巧与Httpcontext)
查看>>
float数据在内存中是怎么存储的
查看>>
开发经验和习惯
查看>>
dedecms 修改标题长度可以修改数据库
查看>>
Matplotlib学习---用matplotlib画直方图/密度图(histogram, density plot)
查看>>
云时代架构读后感(一)
查看>>
MySQL案列之主从复制出错问题以及pt-slave-restart工具的使用
查看>>
在JS中调用JAVA变量
查看>>
linux 查看剩余内存数
查看>>
loadrunner 怎么能得到返回的http状态?
查看>>
《SQL CookBook 》笔记-第三章-多表查询-连接查询
查看>>
测试人员容易遗漏的隐藏缺陷
查看>>
JS方法:数字转换为千分位字符
查看>>
maven+SpringMVC搭建RESTful后端服务框架
查看>>
[HDU5714]拍照
查看>>
[BalkanOI2016]Cruise
查看>>
《陶哲轩实分析》定理10.1.15:导数的链法则
查看>>