supermarket SSM
1.数据库
2.整体空架构(jar包)
3.工程依赖 24节点 build节点
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!--spring对应的版本号-->
<spring.version>4.3.10.RELEASE</spring.version>
</properties>
<!--引入需要的spring 核心jar-->
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency> <!--SpringJDBC需要的jar-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency> <!--spring整合aspect需要的jar-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency> <!--引入spring需要的事务jar包-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency> <!--引入springmvc需要的jar包-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency> <dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency> <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
</dependency> <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency> <!--引入mysql的驱动包-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency> <!--配置jdbc需要的数据源-->
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
</dependency> <dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency> <!--aspectj需要的jar-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.10</version>
</dependency> <dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<!--引入需要的jstl jar-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency> <!-- https://mvnrepository.com/artifact/org.javassist/javassist -->
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
</dependency> <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.3</version>
</dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.9</version>
</dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.8</version>
</dependency> </dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
4.4个配置文件
1.配置web.xml节点
1.context-param
2.编码过滤器
3. lister
4. Springmvc前端控制器
5.静态资源放行,交给Tomcat默认的servelt解决
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!--解决编码的过滤器-->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--监听器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--Springmvc配置,前端控制器,就是一个Servlet-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
</web-app>
2.配置mybatis-config.xml
<?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>
<!--别名-->
<typeAliases>
<package name="cn.happy.bean"></package>
</typeAliases>
</configuration>
3.配置jdbc.properties
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql:///smbms
jdbc.userName=root
jdbc.password=1234
4.配置applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--包扫描器-->
<context:component-scan base-package="cn.happy"/>
<!--mvc注解驱动 Json Object-->
<mvc:annotation-driven/>
<!--1.数据源 dbcp Spring自带的 c3p0 Druid-->
<!--使用dbcp数据源-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClass}"/>
<property name="url" value="${jdbc.jdbcUrl}"/>
<property name="username" value="${jdbc.userName}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!--2.识别jdbc.properties文件一个节点-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!--3.SessionFactory-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>
<!--4.扫描Mapper-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="cn.happy.dao"/>
</bean> <!--配置jsp显示ViewResolver-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!--事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--9.事务-->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
5.分层
1.Bean
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
//用户
public class User implements Serializable {
private Integer id;
private String userCode;
private String userName;
private String userPassword;
private Integer gender;
private Date birthday;
private String phone;
private String address;
private Integer userType;
private Integer createdBy;
private Timestamp creationDate;
private Integer modifyBy;
private Timestamp modifyDate;
public User() {
}
public User(Integer id, String userCode, String userName, String userPassword, Integer gender, Date birthday, String phone, String address, Integer userType, Integer createdBy, Timestamp creationDate, Integer modifyBy, Timestamp modifyDate) {
this.id = id;
this.userCode = userCode;
this.userName = userName;
this.userPassword = userPassword;
this.gender = gender;
this.birthday = birthday;
this.phone = phone;
this.address = address;
this.userType = userType;
this.createdBy = createdBy;
this.creationDate = creationDate;
this.modifyBy = modifyBy;
this.modifyDate = modifyDate;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUserCode() {
return userCode;
}
public void setUserCode(String userCode) {
this.userCode = userCode;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public Integer getGender() {
return gender;
}
public void setGender(Integer gender) {
this.gender = gender;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Integer getUserType() {
return userType;
}
public void setUserType(Integer userType) {
this.userType = userType;
}
public Integer getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Integer createdBy) {
this.createdBy = createdBy;
}
public Timestamp getCreationDate() {
return creationDate;
}
public void setCreationDate(Timestamp creationDate) {
this.creationDate = creationDate;
}
public Integer getModifyBy() {
return modifyBy;
}
public void setModifyBy(Integer modifyBy) {
this.modifyBy = modifyBy;
}
public Timestamp getModifyDate() {
return modifyDate;
}
public void setModifyDate(Timestamp modifyDate) {
this.modifyDate = modifyDate;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", userCode='" + userCode + '\'' +
", userName='" + userName + '\'' +
", userPassword='" + userPassword + '\'' +
", gender=" + gender +
", birthday=" + birthday +
", phone='" + phone + '\'' +
", address='" + address + '\'' +
", userType=" + userType +
", createdBy=" + createdBy +
", creationDate=" + creationDate +
", modifyBy=" + modifyBy +
", modifyDate=" + modifyDate +
'}';
}
}
3.Dao
1.用户Dao接口层
import cn.happy.bean.User;
import cn.happy.util.PageUtil;
import java.util.List;
import java.util.Map;
/**
* 用户接口层
*/
public interface IUserDao {
//1.登录方法
public User isLog(User user);
//检索所有用户的集合
public List<User> findAllUsers();
//获取总记录数
public int getTotalCount();
//获取单页数据
public List<User> getOnePageData(Map<String, Object> map);
PageUtil getOnePageData(int pageIndex, int pageSize);
}
用户Dao实现层(用Mybatis实现)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.happy.dao.IUserDao">
<!--登录-->
<select id="isLog" parameterType="User" resultType="User">
select userCode,userName FROM smbms_user WHERE userCode=#{userCode} AND userPassword=#{userPassword}
</select> <!--2.检索所有用户集合-->
<select id="findAllUsers" resultType="User">
SELECT * from smbms_user
</select> <!--获取总记录数-->
<select id="getTotalCount" resultType="int">
SELECT count(1) from smbms_user
</select> <!--获取单页数据-->
<select id="getOnePageData" resultType="User">
SELECT * from smbms_user limit #{pageIndex},#{pageSize}
</select> </mapper>
2.Service
import cn.happy.bean.User;
import cn.happy.util.PageUtil;
import java.util.List;
public interface IUserService {
//1.登录方法
public User isLog(User user);
//检索所有用户的集合
public List<User> findAllUsers();
//获取总记录数
public int getTotalCount();
//获取单页数据
public PageUtil getOnePageData(int pageIndex, int pageSize);
}
UserServiceImpl
import cn.happy.bean.User;
import cn.happy.dao.IUserDao;
import cn.happy.service.IUserService;
import cn.happy.util.PageUtil;
import org.springframework.stereotype.Service; import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map; /**
* Created by Administrator on 2017/10/30.
*/
@Service("userService")
public class IUserServiceImpl implements IUserService {
//dao层对象
@Resource(name = "IUserDao")//将Spring容器悬浮的哪个DAO对象赋值给成员变量
private IUserDao userDao;
@Override
public User isLog(User user) {
System.out.println("service");
return userDao.isLog(user);
}
@Override
public List<User> findAllUsers() {
return userDao.findAllUsers();
}
@Override
public int getTotalCount() {
return 0;
}
@Override
public PageUtil getOnePageData(int pageIndex, int pageSize) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("pageIndex", pageIndex * pageSize);
map.put("pageSize", pageSize);
PageUtil page = new PageUtil();//实例化一个PageUtil对象
page.setPageSize(pageSize);//给PageUtil属性赋值
page.setPageIndex(pageIndex);//给PageUtil的pageIndex赋值
int totalCount = userDao.getTotalCount();
page.setTotalRecords(totalCount);
int totalPage = page.getTotalRecords() % page.getPageSize() == 0 ? page.getTotalRecords() / page.getPageSize() : page.getTotalRecords() / page.getPageSize() + 1;
page.setTotalPages(totalPage);
List<User> list = userDao.getOnePageData(map);
page.setList(list);
return page;
}
}
supermarket SSM的更多相关文章
- 【SSM框架】Spring + Springmvc + Mybatis 基本框架搭建集成教程
本文将讲解SSM框架的基本搭建集成,并有一个简单demo案例 说明:1.本文暂未使用maven集成,jar包需要手动导入. 2.本文为基础教程,大神切勿见笑. 3.如果对您学习有帮助,欢迎各种转载,注 ...
- springmvc 多数据源 SSM java redis shiro ehcache 头像裁剪
获取下载地址 QQ 313596790 A 调用摄像头拍照,自定义裁剪编辑头像 B 集成代码生成器 [正反双向](单表.主表.明细表.树形表,开发利器)+快速构建表单; 技术:31359679 ...
- SSM项目搭建(提供源码)
1创建web动态项目,项目结构截图 2.配置日志文件 #\u5B9A\u4E49LOG\u8F93\u51FA\u7EA7\u522B log4j.rootLogger=INFO,Console,Fi ...
- activiti工作流的web流程设计器整合视频教程 SSM和独立部署
本视频为activiti工作流的web流程设计器整合视频教程 整合Acitiviti在线流程设计器(Activiti-Modeler 5.21.0 官方流程设计器) 本视频共讲了两种整合方式 1. 流 ...
- activiti工作流的web流程设计器整合视频教程 SSM 和 独立部署
本视频为activiti工作流的web流程设计器整合视频教程 整合Acitiviti在线流程设计器(Activiti-Modeler 5.21.0 官方流程设计器) 本视频共讲了两种整合方式 1. 流 ...
- SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis)【转】
使用SSM(Spring.SpringMVC和Mybatis)已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方.之前没有记录SSM整合 ...
- Maven+Spring+Spring MVC+MyBatis+MySQL,搭建SSM框架环境【转】
项目建设完成之后的结构: 数据库的表结构如下: 环境建设:搭建Maven环境.Tomcat环境.需要MySql 数据库支持,使用的编程工具Eclipse (这些是前期准备): 开始创建工程: 1.创建 ...
- java web后台开发SSM框架(Spring+SpringMVC+MyBaitis)搭建与优化
一.ssm框架搭建 1.1创建项目 新建项目后规划好各层的包. 1.2导入包 搭建SSM框架所需包百度云链接:http://pan.baidu.com/s/1cvKjL0 1.3整合spring与my ...
- SSM整合(三):Spring4与Mybatis3与SpringMVC整合
源码下载 SSMDemo 上一节整合了Mybatis3与Spring4,接下来整合SpringMVC! 说明:整合SpringMVC必须是在web项目中,所以前期,新建的就是web项目! 本节全部采用 ...
随机推荐
- ps 常用命令
1.ps aux:显示所有进程信息 2.ps -u root:显示指定用户信息 3.ps -ef:显示所有进程信息,连同命令行 ps -ef|grep ssh 4.ps -axjf 显示程序树 5.p ...
- CENTOS 7 和 JDK 添加中文字体
写在前面的话 当运维总是遇到各种奇奇怪怪的问题,比如新的 JAVA 项目上线,login 界面有个验证码,结果部署后发现,要么显示的奇奇怪怪,要么压根不显示. 或者在使用一些开源的 JAVA 项目的时 ...
- HTTP状态码了解
1xx - - 消息 2xx - - 成功 3xx - - 重定向 4xx - - 请求错误 5xx - - 服务器错误 1xx-信息提示 这些状态代码表示临时的响应.客户端在收到 ...
- Qt 学习之路 2(25):画刷和画笔
Home / Qt 学习之路 2 / Qt 学习之路 2(25):画刷和画笔 Qt 学习之路 2(25):画刷和画笔 豆子 2012年11月5日 Qt 学习之路 2 17条评论 前面一章我们提 ...
- cs231n学习笔记(二)图像分类
图像分类可说是计算机视觉中的基础任务同时也是核心任务,做好分类可为检测,分割等高阶任务打好基础. 本节课主要讲了两个内容,K近邻和线性分类器,都是以猫的分类为例. 一. K近邻 以猫的分类为例,一张含 ...
- [Leetcode]015. 3Sum
public class Solution { public List<List<Integer>> threeSum(int[] num) { Arrays.sort(num ...
- IOS 11 永不升级方法
解决一直跳苹果升级提示终极解决方法:安装方法很简单,1:进设置-通用-存储空间与iCloud用量-管理储存空间.选择ios xxx 点击他,点删除[如果没有就略过]2:点击:https://oldca ...
- mybatis主键是在insert前生成还是之后生成
oracle sequence 推荐每个表使用自己的sequence mysql 使用每个表的autoincreate来当主键 mybatis 操作insert时 主键的生成是在插入之前 还是之后? ...
- SQL SERVER数据库 三种 恢复模式
SQL SERVER 2005 以后三种恢复模式: 简单(Sample),完全(Full),大批量(Bulk_Logged) 完全备份模型 完全备份模式是指在出现数据文件毁坏时丢失数据的风险最小.如果 ...
- Kafka Intro - Configuration
#Notes: /opt/kafka/config/zookeeper.properties sample # the directory where the snapshot is stored.d ...