首先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