SpringBoots的使用

来源:互联网 发布:51单片机控制机箱风扇 编辑:程序博客网 时间:2024/06/08 01:26

1.如果使用maven工程直接配置pox.xml文件自动下载jar包和依赖的包

<project xmlns="http://maven.apache.org/POM/4.0.0" 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">    <modelVersion>4.0.0</modelVersion>    <groupId>com.xdl</groupId>    <artifactId>springboot1.o</artifactId>    <version>0.0.1-SNAPSHOT</version>    <packaging>war</packaging>    <parent>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-parent</artifactId>        <version>1.5.6.RELEASE</version>    </parent>    <dependencies>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>            <version>1.5.6.RELEASE</version>        </dependency>        <dependency>            <groupId>mysql</groupId>            <artifactId>mysql-connector-java</artifactId>            <version>5.1.30</version>        </dependency>        <dependency>            <groupId>org.mybatis.spring.boot</groupId>            <artifactId>mybatis-spring-boot-starter</artifactId>            <version>1.2.1</version>        </dependency>    </dependencies>    <build>        <plugins>            <plugin>                <groupId>org.springframework.boot</groupId>                <artifactId>spring-boot-maven-plugin </artifactId>            </plugin>        </plugins>    </build></project>

或者自己导入jar包

这里写图片描述

2.创建springboot启动类和main方法

package com.xdl.server;import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.context.annotation.ComponentScan;import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;//扫描springmvc的controller@ComponentScan(basePackages = { "com.xdl.controller", "com.xdl.service" })//扫描mybatis部分的道接口和mapper方法@MapperScan(basePackages = { "com.xdl.dao" })//自动加载所有需要的bean@EnableAutoConfigurationpublic class MainServer extends WebMvcConfigurerAdapter {    @Override    public void configureContentNegotiation(            ContentNegotiationConfigurer configurer) {        configurer.favorPathExtension(false);    }    public static void main(String[] args) {        SpringApplication.run(MainServer.class, args);    }}

3.项目结构详解

这里写图片描述

原创粉丝点击