搭建springboot+ssm项目--环境

1.创建maven工程
搭建springboot+ssm项目--环境_第1张图片
image.png

添加一个resources文件夹


搭建springboot+ssm项目--环境_第2张图片
image.png
2.在pom文件导入springboot依赖

  4.0.0

  com.cwh
  webDemo
  0.0.1-SNAPSHOT
  jar
  
  
  
      org.springframework.boot
      spring-boot-starter-parent
      1.5.10.RELEASE
      
  

  webDemo
  http://maven.apache.org

  
    UTF-8
  

  
  
    
      junit
      junit
      3.8.1
      test
    
    
    
            org.springframework.boot
            spring-boot-starter-web
        
        
        
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
    
  
  


3.在resource文件夹创建application.properties
server.port=8006
logging.level.com.cwh.webDemo=debug
4.在java文件夹下分好包
搭建springboot+ssm项目--环境_第3张图片
image.png

在最顶层的包中创建springboot启动类SpringDemoApplication.java

package com.cwh.webDemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringDemoApplication.class, args);
    }
}

5.测试springboot是否搭建成功

在控制层写个testController

package com.cwh.webDemo.Controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/test")
public class TestController {
    
    @RequestMapping("/sayHello")
    @ResponseBody
    public String sayHello() {
        return "hello";
        
    }

}

启动springDemoApplicationg.java


搭建springboot+ssm项目--环境_第4张图片
image.png

在浏览器访问


搭建springboot+ssm项目--环境_第5张图片
image.png
6.在pom文件添加mybatis,逆向生成mapper及数据库依赖

  4.0.0

  com.cwh
  webDemo
  0.0.1-SNAPSHOT
  jar
  
  
  
      org.springframework.boot
      spring-boot-starter-parent
      1.5.10.RELEASE
      
  

  webDemo
  http://maven.apache.org

  
    UTF-8
  

  
  
    
      junit
      junit
      3.8.1
      test
    
    
    
        org.springframework.boot
        spring-boot-starter-web
    
    
    
    
        org.springframework.boot
        spring-boot-starter-thymeleaf
    
    
    
    
       mysql
       mysql-connector-java
       8.0.11
    

        
    
       org.mybatis.spring.boot
       mybatis-spring-boot-starter
       1.3.1
    
        
    
    

    
    
       org.mybatis.generator
       mybatis-generator-core
       1.3.2
    
        
    
  
  
        
    
        
            
                src/main/java
                
                    **/*.properties
                    **/*.xml
                
                false
            
            
                src/main/resources
                
                    **/*.properties
                    **/*.xml
                
                false
            
        
    
        
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
            
            
                    org.mybatis.generator
                    mybatis-generator-maven-plugin
                    1.3.2
                    
                        src/main/resources/generatorConfig.xml
                        true
                        true
                    
                    
                        
                            Generate MyBatis Artifacts
                            
                                generate
                            
                        
                    
                    
                        
                            org.mybatis.generator
                            mybatis-generator-core
                            1.3.2
                        
                    
                
                
                    org.apache.maven.plugins
                    maven-surefire-plugin
                    2.19.1
                    
                        true
                    
                

                
                    org.apache.maven.plugins
                    maven-resources-plugin
                    3.0.1
                    
                        UTF-8
                    
                
            
        
        
     
  

7.在resources文件夹下创建逆向生成的配置文件generatorConfig.xml
  
  
  
      
        
      
          
              
              
          
          
          
          
          
              
              
          
          
          
              
              
              
              
          
          
          
              
              
          
          
          
              
              
          
          
      
      

需要对应项目修改生成的包及表名

8.在applicationg.xml配置数据库
server.port=8006

logging.level.com.cwh.webProject=debug

spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/shop_system?serverTimezone=GMT&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456

mybatis.type-aliases-package=com.cwh.webDemo.Entity
mybatis.mapper-locations: classpath:mapper/*Mapper.xml

后面指定的是mapper.xml文件的位置

9.开始逆向生成
搭建springboot+ssm项目--环境_第6张图片
image.png

搭建springboot+ssm项目--环境_第7张图片
image.png

将生成的文件放到项目对应的位置


搭建springboot+ssm项目--环境_第8张图片
image.png
10.编写server测试能否走通

在启动类中添加dao扫描

package com.cwh.webDemo;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan({"com.cwh.webDemo.Dao"})
public class SpringDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringDemoApplication.class, args);
    }
}

ClientServer


import java.util.List;

import com.cwh.webDemo.Entity.Client;

public interface ClientServer {
    
    public List getAll();

}

ClientServerImpl

package com.cwh.webDemo.ServerImpl;

import java.util.List;

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

import com.cwh.webDemo.Dao.ClientMapper;
import com.cwh.webDemo.Entity.Client;
import com.cwh.webDemo.Entity.ClientExample;
import com.cwh.webDemo.Server.ClientServer;

@Service
public class ClientServerImpl implements ClientServer {
    
    @Autowired
    private ClientMapper clientMapper;

    public List getAll() {
        ClientExample clientExample = new ClientExample();
        
        return clientMapper.selectByExample(clientExample);
    }

}

Controller

@RequestMapping("/getClient")
    @ResponseBody
    public void getClient() {
        
         System.out.println(clientServer.getAll());
        
    }
搭建springboot+ssm项目--环境_第9张图片
image.png

控制台


image.png

完整application文件

server.port=8006

logging.level.com.cwh.webDemo=debug

spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/shop_system?serverTimezone=GMT&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456

mybatis.type-aliases-package=com.cwh.webDemo.Entity
mybatis.mapper-locations: classpath:mapper/*Mapper.xml

完整pom文件

  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4.0.0

  com.cwh
  webDemo
  0.0.1-SNAPSHOT
  jar
  
  
  
      org.springframework.boot
      spring-boot-starter-parent
      1.5.10.RELEASE
      
  

  webDemo
  http://maven.apache.org

  
    UTF-8
  

  
  
    
      junit
      junit
      3.8.1
      test
    
    
    
        org.springframework.boot
        spring-boot-starter-web
    
    
    
    
        org.springframework.boot
        spring-boot-starter-thymeleaf
    
    
    
    
       mysql
       mysql-connector-java
       8.0.11
    

        
    
       org.mybatis.spring.boot
       mybatis-spring-boot-starter
       1.3.1
    
        
    
    

    
    
       org.mybatis.generator
       mybatis-generator-core
       1.3.2
    
        
    
  
  
        
    
        
            
                src/main/java
                
                    **/*.properties
                    **/*.xml
                
                false
            
            
                src/main/resources
                
                    **/*.properties
                    **/*.xml
                
                false
            
        
    
        
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
            
            
                    org.mybatis.generator
                    mybatis-generator-maven-plugin
                    1.3.2
                    
                        src/main/resources/generatorConfig.xml
                        true
                        true
                    
                    
                        
                            Generate MyBatis Artifacts
                            
                                generate
                            
                        
                    
                    
                        
                            org.mybatis.generator
                            mybatis-generator-core
                            1.3.2
                        
                    
                
                
                    org.apache.maven.plugins
                    maven-surefire-plugin
                    2.19.1
                    
                        true
                    
                

                
                    org.apache.maven.plugins
                    maven-resources-plugin
                    3.0.1
                    
                        UTF-8
                    
                
            
        
        
     
  

你可能感兴趣的:(搭建springboot+ssm项目--环境)