ssm框架搭建(详细)

ssm框架搭建

 

开发环境:eclipse + jdk18 + tomcat8.5 + maven3.6 + mysql5.10

 

开发环境配置教程(<—点击)

 

项目结构:

ssm框架搭建(详细)_第1张图片

 

 

 ssm框架搭建(详细)_第2张图片

 

 数据库:

--用户表
CREATE TABLE `user` ( `userid`
int(11) NOT NULL AUTO_INCREMENT COMMENT '用户编号', `username` varchar(50) NOT NULL COMMENT '用户名', `password` varchar(50) NOT NULL COMMENT '密码', PRIMARY KEY (`userid`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8


--角色表

CREATE TABLE `role` (
`roleid` int(11) NOT NULL AUTO_INCREMENT COMMENT '角色编号',
`rolename` varchar(50) NOT NULL COMMENT '角色名',
`userid` int(11) DEFAULT NULL COMMENT '用户外键',
PRIMARY KEY (`roleid`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8

 

--中间表

CREATE TABLE `permission` (
`permissionid` int(11) NOT NULL AUTO_INCREMENT COMMENT '权限编号',
`userid` int(11) DEFAULT NULL COMMENT '用户外键',
`roleid` int(11) DEFAULT NULL COMMENT '角色外键',
PRIMARY KEY (`permissionid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

 

 

 

User实体类:

/****************************************************************
**类  名:User
**描  述:
**创建者:ycs
**创建时间:2020-01-0113:42:06
****************************************************************/

package cn.ssm.entity;

/**
*(user)
*
*@author ycs
*/
public class User implements java.io.Serializable {
    /** 版本号 */
    private static final long serialVersionUID = 8510755126090371199L;

    /** 用户编号 */
    private Integer userid;

    /** 用户名 */
    private String username;

    /** 密码 */
    private String password; /** * 获取用户编号 * * @return 用户编号 */ public Integer getUserid() { return this.userid; } /** * 设置用户编号 * * @param userid * 用户编号 */ public void setUserid(Integer userid) { this.userid = userid; } /** * 获取用户名 * * @return 用户名 */ public String getUsername() { return this.username; } /** * 设置用户名 * * @param username * 用户名 */ public void setUsername(String username) { this.username = username; } /** * 获取密码 * * @return 密码 */ public String getPassword() { return this.password; } /** * 设置密码 * * @param password * 密码 */ public void setPassword(String password) { this.password = password; } }

 

userMapper.xml







    
    
        
        
        
    
    
    
    
        userid, username, password
    
    
    
    
    

 

dao层

package cn.ssm.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.ssm.entity.User;

@Repository("userMapper")
public interface UserMapper {

    List findUserAll();
}

 

service层

package cn.ssm.service;

import java.util.List;

import cn.ssm.entity.User;

public interface UserService {
    
    List findUserAll();
}

 

serviceimpl层

package cn.ssm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.ssm.dao.UserMapper;
import cn.ssm.entity.User;
import cn.ssm.service.UserService;

@Service("userService")
public class UserServiceImpl implements UserService{
    
    @Autowired
    private UserMapper userMapper;

    @Override
    public List findUserAll() {
        // TODO Auto-generated method stub
        return userMapper.findUserAll(); } }

 

controller层

package cn.ssm.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import cn.ssm.entity.User;
import cn.ssm.service.UserService;

@Controller
public class UserController extends ModelAndView{

    @Autowired
    private UserService userService;
    
    @RequestMapping("/findUser")
    public String findUserAll(Model model) {
        List users=userService.findUserAll(); model.addAttribute("users",users); System.out.println(users); return "index"; } }

 

spring-mvc.xml

  
  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans    
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd    
                        http://www.springframework.org/schema/context    
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd    
                        http://www.springframework.org/schema/mvc    
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">  
  

    
    
    
    
    
   
    
              

 

spring-mybatis.xml



    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans  
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
                        http://www.springframework.org/schema/context  
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd  
                        http://www.springframework.org/schema/mvc  
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
    
    
    
    
    
        
    

    
        destroy-method="close">
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    

    
    
        
        
        
    

    
    
        
        
    

    
    
        
    

 

web.xml

"http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
                        version="3.0">
    Archetype Created Web Application
          
      
        contextConfigLocation  
        classpath:spring/spring-mybatis.xml  
      
      
      
        encodingFilter  
        class>org.springframework.web.filter.CharacterEncodingFilterclass>  
        <async-supported>trueasync-supported>  
          
            encoding  
            UTF-8  
          
      
      
        encodingFilter  
        /*  
      
  
      
      
        org.springframework.web.context.ContextLoaderListener  
      
      
      
        org.springframework.web.util.IntrospectorCleanupListener  
      
  
      
      
        SpringMVC  
        org.springframework.web.servlet.DispatcherServlet  
          
            contextConfigLocation  
            classpath:spring/spring-mvc.xml  
          
        1  
        true  
      
      
        SpringMVC  
          
        /  
      
      
        /index.jsp  
      

 

 

jdbc.properties

#jdbc驱动类
driver=com.mysql.jdbc.Driver

#服务器url
url=jdbc:mysql://localhost:3306/ycs?useUnicode=true&characterEncoding=utf-8
#服务器用户名
username=
#服务器密码
password=


initialSize=0  
 maxActive=20  maxIdle=20  minIdle=1  maxWait=60000

 

log4j.properties

#配置根Logger
log4j.rootLogger=DEBUG,INFO,Console,File
#配置日志信息输出目的地Appender
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
#配置日志信息的格式(布局)
log4j.appender.Console.layout = org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%c] - %m%n ###\u663E\u793ASQL\u8BED\u53E5\u90E8\u5206 log4j.logger.com.ibatis=DEBUG log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG log4j.logger.java.sql.Connection=DEBUG log4j.logger.java.sql.Statement=DEBUG log4j.logger.java.sql.PreparedStatement=DEBUG #\u6587\u4EF6\u5927\u5C0F\u5230\u8FBE\u6307\u5B9A\u5C3A\u5BF8\u7684\u65F6\u5019\u4EA7\u751F\u4E00\u4E2A\u65B0\u7684\u6587\u4EF6 log4j.appender.File = org.apache.log4j.RollingFileAppender #\u6307\u5B9A\u8F93\u51FA\u76EE\u5F55 log4j.appender.File.File = logs/ssm.log #\u5B9A\u4E49\u6587\u4EF6\u6700\u5927\u5927\u5C0F log4j.appender.File.MaxFileSize = 10MB # \u8F93\u51FA\u6240\u4EE5\u65E5\u5FD7\uFF0C\u5982\u679C\u6362\u6210DEBUG\u8868\u793A\u8F93\u51FADEBUG\u4EE5\u4E0A\u7EA7\u522B\u65E5\u5FD7 log4j.appender.File.Threshold = ALL log4j.appender.File.layout = org.apache.log4j.PatternLayout log4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n

 

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>




"UTF-8">
用户信息显示







    
class="div1" align="center"> "1" style="height: 100px; width: 500px;"> class="tr1" height="20px"> var="each" items="${users }"> class="tr1">
"4" >用户信息显示
用户编号 用户名 密码 操作
"td1" align="center">${each.userid } "td1" align="center">${each.username } "td1" align="center">${each.password } "td1" align="center">"">修改"">删除

 

 

pom.xml


    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4.0.0
    cn.ssm
    SSM
    0.0.1-SNAPSHOT
    war
    SSM
    我的ssm练习

    http://maven.apache.org
    
        
        4.0.9.RELEASE
        
        3.2.8
        
        1.7.7
        1.2.17
    

    
        
            junit
            junit
            4.11
            
            test
        

        
        
            commons-codec
            commons-codec
            1.9
        
        
        
            org.springframework
            spring-core
            ${spring.version}
        

        
            org.springframework
            spring-web
            ${spring.version}
        
        
            org.springframework
            spring-oxm
            ${spring.version}
        
        
            org.springframework
            spring-tx
            ${spring.version}
        

        
            org.springframework
            spring-jdbc
            ${spring.version}
        

        
            org.springframework
            spring-webmvc
            ${spring.version}
        
        
            org.springframework
            spring-aop
            ${spring.version}
        

        
            org.springframework
            spring-context-support
            ${spring.version}
        

        
            org.springframework
            spring-test
            ${spring.version}
        
        
        
            org.mybatis
            mybatis
            ${mybatis.version}
        
        
        
            org.mybatis
            mybatis-spring
            1.2.2
        
        
        
            javax
            javaee-api
            7.0
        
        
        
            mysql
            mysql-connector-java
            5.1.30
        

        
        
            commons-dbcp
            commons-dbcp
            1.2.2
        
        
        
            jstl
            jstl
            1.2
        
        
        
        
            log4j
            log4j
            ${log4j.version}
        


        
        
            com.alibaba
            fastjson
            1.1.41
        


        
            org.slf4j
            slf4j-api
            ${slf4j.version}
        

        
            org.slf4j
            slf4j-log4j12
            ${slf4j.version}
        
        
        
        
            org.codehaus.jackson
            jackson-mapper-asl
            1.9.13
        
        
        
            commons-fileupload
            commons-fileupload
            1.3.1
        
        
            commons-io
            commons-io
            2.4
        
        
            commons-codec
            commons-codec
            1.9
        
    

    
        SSM
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    1.8
                    1.8
                    UTF-8
                
            
        
    

你可能感兴趣的:(ssm框架搭建(详细))