SSM整合,直接抄,项目起不来算我输

SSM整合,直接抄,项目起不来算我输,第1张

SSM整合,直接抄,项目起不来算我输 哪些人适合

快速搭建SSM环境知道其中原理,或者不深究原理的对版本的追求不是非最新不可的 1、项目结构

2、从上往下直接COPY 2-1、类文件

com.test.ssm.controller.StudentController

package com.test.ssm.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("getStudent")
public class StudentController{
    @RequestMapping("student")
    public String toStudent() {
        return "student"; //转到是哪个 视图文件 --》对应的就是student.jsp
    }
}

com.test.ssm.mapper.StudentMapper

package com.test.ssm.mapper;

import com.test.ssm.pojo.Student;
import org.apache.ibatis.annotations.Param;

public interface StudentMapper {
    Student getStudent(@Param("id") Integer id);
}

com.test.ssm.pojo.Student

package com.test.ssm.pojo;

import lombok.Data;
@Data
public class Student {
    private Integer id;
    private String name;
    private Integer age;
}

2-2、resources下的配置文件

mybatis/mapper/StudentMapper.xml





    
		select * from student where id = #{id}
	


mybatis/mybatis-config.xml




    
        
        
    

spring/applicationContext.xml



    
    

    
    
        
        
        
        
    
    
    
        
        
    

spring/applicationContext-mybatis.xml



    
    
        
        
        
        
        
        
        
        
    

    
    
        
    


spring/applicationContext-service.xml


    
    

spring/springmvc-servlet.xml




    
    
    
    
    
        
        
    

jdbc.properties(直接在resources下面)

jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/jack
jdbc.username=root
jdbc.password=root

log4j.properties(直接在resources下面;没有解决最近爆出来的漏洞的,就是自己搭的小demo)

log4j.rootLogger=INFO,A1
log4j.logger.org.apache=INFO
log4j.appender.A1.Target=System.err
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c]-[%p] %m%n
2-3、webapp下面的

/WEB-INF/views/student.jsp

    
        ID
        用户名
        姓名
        年龄
        生日
        创建日期
        更新日期
    

/WEB-INF/web.xml



    ssm_integrate


    
    
        org.springframework.web.context.ContextLoaderListener
    
    
        contextConfigLocation
        classpath:spring/applicationContext*.xml
    
    
    
        encodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            UTF8
        
    
    
        encodingFilter
        /*
    

    
    
        springmvc
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:spring/springmvc-servlet.xml
        
        1
    

    
        springmvc
        /
    

    
        index.jsp
    

webapp下面的index.jsp

<%--WEB-INF下的资源不能通过URL直接访问,需要Controller转发,所以index.jsp放外面--%>

    Hello World

3、工程的pom文件


    4.0.0

    cn.itcast.ssm
    ssm_integrate
    1.0-SNAPSHOT
    war

    
    
        4.12
        5.0.10.RELEASE
        3.4.6
        1.3.2
        1.2.15
        5.1.32
        1.6.4
        2.9.0
        1.0.9
        4.3.5
        1.2
        2.5
        2.0
        2.5
        3.3.2
        1.3.2
    


    
        
            org.springframework
            spring-context
            ${spring.version}
        
        
            org.springframework
            spring-core
            ${spring.version}
        
        
            org.springframework
            spring-beans
            ${spring.version}
        
        
        
            junit
            junit
            ${junit.version}
            test
        

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

        
        
            org.mybatis
            mybatis
            ${mybatis.version}
        
        
            org.mybatis
            mybatis-spring
            ${mybatis.spring.version}
        


        
        
            mysql
            mysql-connector-java
            ${mysql.version}
        

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


        
        
            com.alibaba
            druid
            ${druid.version}
        


        
        
            jstl
            jstl
            ${jstl.version}
        
        
            javax.servlet
            servlet-api
            ${servlet-api.version}
            provided
        
        
            javax.servlet
            jsp-api
            ${jsp-api.version}
            provided
        
        
            org.springframework
            spring-test
            ${spring.version}
            test
        
        
            org.projectlombok
            lombok
            1.18.12
        
    

    
        ${project.artifactId}
        
            
            
                org.apache.maven.plugins
                maven-resources-plugin
                2.7
                
                    UTF-8
                
            
            
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.2
                
                    1.7
                    1.7
                    UTF-8
                
            
            
            
                org.apache.tomcat.maven
                tomcat7-maven-plugin
                2.2
                
                    9090
                    /
                
            
        
    


4、最后补一个测试

com.test.ssm.mapper.StudentMapperTest

package com.test.ssm.mapper;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring/applicationContext.xml",
        "classpath:spring/applicationContext-mybatis.xml" })
public class StudentMapperTest {
@Autowired
private StudentMapper studentMapper;
    @Test
    public void getStudent() {
        System.out.println(studentMapper.getStudent(1));
    }
}
5、SQL语句

studen表(我的url配置的是jack数据库下,请自行创建在对应的库)

CREATE TABLE `student` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `age` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;

插入数据

insert into student (name,age) values ('张三',18);

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5707467.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存