2.前端
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+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <table width="80%" align="center"> <tr> <td>编号</td> <td>姓名</td> <td>密码</td> </tr> <c:forEach items="${list}" var="bean"> <tr> <td>${bean.id}</td> <td>${bean.username}</td> <td>${bean.password}</td> </tr> </c:forEach> </table> </body> </html>
3.后端
User
package com.sjsq.model; /** * 实体类 * @author shuijianshiqing * @date 2020/6/21 10:21 */ public class User { private Integer id; private String username; private String password; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public String toString() { return "User{" + "id=" + id + ", username='" + username + '\'' + ", password='" + password + '\'' + '}'; } }
UserDao
package com.sjsq.dao; import com.sjsq.model.User; import java.util.List; /** * @author shuijianshiqing * @date 2020/6/21 10:29 */ public interface UserDao { /** * 获取所有用户信息 * @return */ public List<User> list(); }
UserDaoImpl
package com.sjsq.dao.impl; import com.sjsq.dao.UserDao; import com.sjsq.model.User; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.support.SqlSessionDaoSupport; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import java.util.List; /** * @author shuijianshiqing * @date 2020/6/21 10:30 */ @Repository("userDao") public class UserDaoImpl extends SqlSessionDaoSupport implements UserDao { @Autowired @Override public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) { super.setSqlSessionFactory(sqlSessionFactory); } /** * 返回查询结果 * @return */ public List<User> list() { return this.getSqlSession().selectList("com.sjsq.model.user.mapper.list"); } }
UserService
package com.sjsq.service; import com.sjsq.model.User; import java.util.List; /** * @author shuijianshiqing * @date 2020/6/21 10:38 */ public interface UserService { public List<User> list(); }
UserServiceImpl
package com.sjsq.service.impl; import com.sjsq.dao.UserDao; import com.sjsq.model.User; import com.sjsq.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; /** * @author shuijianshiqing * @date 2020/6/21 10:38 */ @Service("userService") public class UserServiceImpl implements UserService { @Autowired private UserDao userDao; public void setUserDao(UserDao userDao){ this.userDao = userDao; } public List<User> list() { return userDao.list(); } }
UserController
package com.sjsq.controller; import com.sjsq.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; /** * @author shuijianshiqing * @date 2020/6/21 10:42 */ @Controller public class UserController { @Autowired private UserService userService; // Spring使用set方法进行依赖注入 public void setUserService(UserService userService) { this.userService = userService; } /** * 查询所有用户信息 * @param map * @return */ @RequestMapping("/list") public String list(ModelMap map){ map.addAttribute("list", userService.list()); return "list"; } }
三、数据库文件
drop database if exists maven-ssm-demo; create database maven-ssm-demo; drop table if exists `user`; create table `user` ( `id` int(11) not null auto_increment, `username` varchar(255) default null, `password` varchar(255) default null, primary key (`id`) ); insert into `user` values (1, 'sjsq', '123456');
四、运行项目
浏览器输入:http://localhost:8080/list.do,就可以访问到页面了。
五、感悟及其他
1.感悟
SSM搭建过程,主要是配置文件要写正确。其次,要注意数据库的配置,这里使用的mysql8.0。其他就没有什么了。但是要理解SSM原理是较为复杂的,如果要是再读源码,要求就要更高。
2.商务合作
要是你自己对于本项目有定制化开发需求或者有什么其他问题,可以联系:
博主QQ:3079118617
请备注:来源CSDN
注意:有偿服务哦
3.其他
你要是想做非SSM图书管理系统,请移步:
图书管理系统
图书管理系统-添加管理增删改查功能
你要是想做非SSM学生成绩管理系统,请移步:
学生成绩管理系统
后续我也会进行开发SSM的各种管理系统,欢迎关注我的博客。
鸡汤:每一次总结,都是对你能力的提升。