spring boot学习(一)---建项目结构
来源:互联网 发布:tv霸网络电视直播 编辑:程序博客网 时间:2024/05/19 23:57
最近开始学习spring boot 在这里记录下,学习内容是根据慕课网的廖师兄的课程结合自己编写的。
一 搭建项目结构
1.使用eclipse 创建maven项目
选择 maven-archetype-webapp
在pom.xml中填写所需jar包,注意:需要继承父类的 pring-boot-starter-parent
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.springboot.api</groupId> <artifactId>springboot</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>springboot Maven Webapp</name> <url>http://maven.apache.org</url> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.1.RELEASE</version> <relativePath></relativePath> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency> <!--jpa的jar包 ,操作数据库的,类似hibernate--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <!--mysql驱动--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!--thymeleaf模板jar,是很不错的html数据传递取值,类似jsp的jstl--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> <finalName>springboot</finalName> </build></project>
2.创建对应项目结构
(我的是这个样子)
3.编写配置文件application.properties
spring.datasource.platform=mysqlspring.datasource.url=jdbc:mysql://127.0.0.1:3306/springboot?useUnicode=yes&characterEncoding=UTF-8spring.datasource.username=spring.datasource.password=spring.datasource.driverClassName=com.mysql.jdbc.Driver# Advanced configuration...spring.datasource.max-active=50spring.datasource.max-idle=6spring.datasource.min-idle=2spring.datasource.initial-size=6#create tablespring.jpa.hibernate.ddl-auto=validateserver.port=8080#server.context-path=/bootserver.session-timeout=30server.tomcat.uri-encoding=UTF-8
(username和password自行填写)
spring boot 同时也支持yaml配置
格式如下
server: port: 8080
4.编写启动类 Application.java
package com.boot;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;@SpringBootApplicationpublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}
编写测试用的Controller HelloController.java
5.编写测试用的Controller HelloController.java
“`
package com.boot.web;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@ResponseBody@RequestMapping(value="/hello" ,method = RequestMethod.GET)
public String say(){
return “spring boot!”;
}
}
回到Application.java 文件下 启动main函数
第一个springboot应用就启动了
在浏览器中输入 http://localhost:8080/hello
可以看到spring boot!
第一个spring boot应用就搭建完成
- spring boot学习(一)---建项目结构
- Spring boot学习(一)创建JavaEE初始化项目
- Spring-Boot学习笔记(一) 项目搭建和HelloWold
- Spring Boot学习(一)
- Spring Boot学习(一)
- Spring Boot学习(一)
- spring boot 学习(一)
- Spring Boot学习(一)
- Spring Boot项目结构推荐
- Spring Boot 学习(一)
- Spring Boot学习(一)
- Spring Boot学习一
- Spring Boot学习(一)
- Spring Boot学习(一)
- spring boot零基础学习 spring boot简介(一)
- Spring Boot 学习(一) 快速搭建SpringBoot 项目
- Spring Boot 学习(一) 快速搭建SpringBoot 项目
- 一、spring boot项目搭建
- 【Linux文件目录命令】ls命令
- idea 破解网址
- Verilog实用操作(不定时更新)
- Python 爬虫环境搭建
- vim使用小结
- spring boot学习(一)---建项目结构
- ThinkPHP网页打开的时候显示错误位置
- adb remount 系统提示只读文件系统Read-only file system,解决用adb disable-verity
- LeetCode 48 Rotate Image
- angular 过滤器
- Redis 讲解系列之 Redis的主从复制(一)
- apache和tomcat无法启动,调试小技巧
- Android App 改变状态栏颜色
- 木乃伊迷宫(存在一些bug,后面有改过的)