解決SpringBoot項目出現Whitelabel Error Page的問題(上)


1.使用STS創建SpringBoot項目




創建的SpringBoot項目默認是沒有web.xml文件的,需要手動添加。

SpringBoot項目的結構如下:

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));
	}
		
}

參考:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM