1.使用STS创建SpringBoot项目

解决SpringBoot项目出现Whitelabel Error Page的问题(上)
解决SpringBoot项目出现Whitelabel Error Page的问题(上)
解决SpringBoot项目出现Whitelabel Error Page的问题(上)
解决SpringBoot项目出现Whitelabel Error Page的问题(上)

创建的SpringBoot项目默认是没有web.xml文件的,需要手动添加。
解决SpringBoot项目出现Whitelabel Error Page的问题(上)

SpringBoot项目的结构如下:
解决SpringBoot项目出现Whitelabel Error Page的问题(上)

2.遇到Whitelabel Error Page的问题

package com.example.model;

public class Greeting {
	private long id;
	private String content;
	
	public Greeting() {
		
	}
	
	public Greeting(long id, String content) {
		this.id = id;
		this.content = content;
	}
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	
}
package com.example.controller;

import java.util.concurrent.atomic.AtomicLong;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.model.Greeting;

//@RestController = @Controller + @ResponseBody
@RestController
public class GreetingController {
	private static final String template = "Hello, %s!";
	private final AtomicLong counter = new AtomicLong();
	
/*  The Greeting object must be converted to JSON. Thanks to Spring’s HTTP message converter support, 
    you need not do this conversion manually. Because Jackson 2 is on the classpath, 
    Spring’s MappingJackson2HttpMessageConverter is automatically chosen to convert the Greeting instance to JSON.
*/
	@GetMapping("/greeting")
	public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
		return new Greeting(counter.incrementAndGet(), String.format(template, name));
	}
		
}

解决SpringBoot项目出现Whitelabel Error Page的问题(上)

参考:

相关文章:

  • 2022-12-23
  • 2021-11-01
  • 2021-05-24
  • 2022-12-23
  • 2021-04-28
  • 2021-05-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-14
  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
  • 2021-12-21
相关资源
相似解决方案