创建一个springboot工程的步骤

首先new一个工程,选择maven,名字命名为com.bee ,artifactId 为bee,

二、创建new 出每一个module,名字为bee-web,bee-dao,bee-service,bee-client

三、配置maven 文件,修改setting路径,设置为国内下载的地址,

四、删除根目录下的src文件夹

五、主pom.xml配置把springboot的包引进来,并且有个springboot 版本,这时候在依赖上面配置一个版本

  <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <srpingboot.version>1.5.6.RELEASE</srpingboot.version>
        <java.version>1.8</java.version>
    </properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${srpingboot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.38</version>
        </dependency>
    </dependencies>
</dependencyManagement>

六、web 的pom的依赖添加,依赖service里的包,freemarker模板包、热部署包、和一个build的插件

 <dependencies>
        <dependency>
            <groupId>com.bee</groupId>
            <artifactId>bee-service</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>
        <!-- 热部署 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
            <scope>true</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!-- 没有该配置,devtools 不生效 -->
                    <fork>true</fork>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

七、service的pom配置,因为service模块重要用到httprequest 这些参数,所以要引入starter-web包、要依赖dao层的包

<dependencies>
    <dependency>
        <groupId>com.bee</groupId>
        <artifactId>bee-dao</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

八、dao的pom配置,这块要引入mysql-connector-java包,驱动包、mybatis包、pagehelper分页包

<dependencies>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.9</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper-spring-boot-starter</artifactId>
        <version>1.2.2</version>
    </dependency>
</dependencies>

九、在web层下的java目录下新建一个包com.compass包,新建一个启动类SpringbootApplication,MainController

@SpringBootApplication
public class SpringbootApplication {
    public static void main(String[] args){
        SpringApplication.run(SpringbootApplication.class,args);
    }
}
@Controller
public class MainController {
    @RequestMapping("/")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("index");
        return modelAndView;
    }
}

十、在web层下的resources目录下新建一个配置 application.properties和一个模板包templates ,并且在templates下新建一个模板index.ftl

server.port=8085
spring.freemarker.cache=false
spring.freemarker.charset=UTF-8
spring.freemarker.content-type=text/html
spring.freemarker.suffix=.ftl
spring.freemarker.template-loader-path=classpath:/templates
spring.freemarker.request-context-attribute=request

#配置数据库连接
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/XXXXXX?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&allowMultiQueries=true
spring.datasource.username=root
spring.datasource.password=XXXXX
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#配置mybatis
mybatis.mapper-locations=classpath:/mappers/*Mapper.xml
mybatis.type-aliases-package=com.XXXXX.XXXXX.XXXXX
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
你好springboot

十一、最后启动功能,页面访问127.0.0.1:8085

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NeilNiu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值