springboot2.0简单的搭建(只是环境的搭建)

使用maven创建项目,工具用的eclipse

贴上pom文件

pom文件
<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.zhinanche</groupId>
	<artifactId>manage_spring_boot</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<!--从Spring Boot继承默认值 -->
	<parent>
		<groupId> org.springframework.boot </groupId>
		<artifactId> spring-boot-starter-parent </artifactId>
		<version> 2.0.0.RELEASE </version>
	</parent>
	<!-- 为Web应用程序添加典型的依赖关系 -->
	<dependencies>
		<dependency>
			<groupId> org.springframework.boot </groupId>
			<artifactId> spring-boot-starter-web </artifactId>
		</dependency>
		<!--fastjson数据配置start -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.2.29</version>
		</dependency>
		<!--fastjson数据配置 end -->
	</dependencies>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>
	<!-- Package as a executable jar -->
	<build>
		<plugins>
			<plugin>
				<groupId> org.springframework.boot </groupId>
				<artifactId> spring-boot-maven-plugin </artifactId>
			</plugin>
		</plugins>
	</build>
</project>

</project>

注:贴上以后下载完jar包update一下maven项目

创建application启动类

application

package cn.springboot.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;

/**
 * spring_boot 启动类
 * @author Administrator
 *
 */
@SpringBootApplication
public class App{

	
	 /**  配置spring_boot返回json数据
     * 使用 @Bean 注入 FastJsonHttpMessageConverter
     * @return
     */
    @Bean
    public HttpMessageConverters fastJsonHttpMessageConverters()
    {
        //1、需要先定义一个 convert 转换消息对象;
        FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();

        //2、添加 fastJson 的配置信息,比如: 是否要格式化返回的Json数据;
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);

        //3、在 Convert 中添加配置信息;
        fastConverter.setFastJsonConfig(fastJsonConfig);

        //4、
        HttpMessageConverter<?> converter = fastConverter;
        return new HttpMessageConverters(converter);
    }
	/**主方法
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		SpringApplication.run(App.class,args);
	}
}

注:启动类加

@SpringBootApplication注解
测试类
package cn.springboot.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.springboot.pojo.User;


/**
 * spring-boot domo controller
 * @author Administrator
 *
 */
@RestController
public class HelloWordController {

	@RequestMapping("hello")
	public User hello(){
		User user = new User();
		user.setId(1);
		user.setName("hello");
		user.setCreateTime(new Date()); 
		return user;
	}

}

App类main方法启动项目

访问 http://localhost:8080/hello

整个项目结构

githup地址 忘记添加忽略了 https://github.com/yinyutaoyyt/spring-boot-demo.git

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值