第一個SpringBoot的Web項目

第一个springboot项目报错内容

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Mar 08 11:29:50 CST 2020
There was an unexpected error (type=Not Found, status=404).
No message available
在这里插入图片描述
正确的解决方法(最简单的入门demo)
1.打开你的Chapter1Main
在这里插入图片描述
2.找到下图这么一行内容在这里插入图片描述
3.把双引号里的内容加到你的地址上(我的就是/test),如下图:
在这里插入图片描述

package com.springboot.chapter1;

@Controller
@EnalbeAutoConfiguration
public class Chapter1Main{
	@RequestMapping("/test")
	@ResponseBody
	public Map<String,String> test(){
		Map<String,String> map=new HashMap<String,String>();
		map.put("key","value");
		return map;
	}
	public static void main (String[] args) throws Exception{
		SpringApplication.run(Chapter1Main.class,args);
	}
}

事实上,Spring Boot的参数配置除了使用properties文件之外,还可以使用yml文件等,它会以下列的优先级顺序进行加载:
•命令行参数;
•来自java:comp/env的JNDI属性;
•Java系统属性(System.getProperties());
•操作系统环境变量;
•RandomValuePropertySource配置的random.*属性值;
•jar包外部的application-{profile}.properties或application.yml(带spring.profile)配置文件;
•jar包内部的application-{profile}.properties或application.ym(带spring.profile)配置文件;
•jar包外部的application.properties或application.yml(不带spring.profile)配置文件;
•jar包内部的application.properties或application.ym(不带spring.profile)配置文件;
•@Configuration注解类上的@PropertySource;
•通过SpringApplication.setDefaultProperties指定的默认属性。
实际上,yml文件的配置与properties文件只是简写和缩进的差别,因此差异并不大,所以本书统一使用properties文件进行配置。对于需要使用yml文件的读者,只是需要稍加改动即可。

yml文件

server:
  port: 8080
  tomcat:
    uri-encoding: UTF-8
    max-connections: 2000
    max-threads: 200

spring:
  datasource:
    name: local-mysql
    url: jdbc:mysql://你的数据库?useUnicode=true&characterEncoding=utf-8&useSSL=false
    username: 你的账户
    password: 你的密码
    driver-class-name: com.mysql.cj.jdbc.Driver

application.properties文件區別

spring.jpa.hibernate.ddl-auto=create

spring.datasource.url=jdbc:mysql://localhost:3306/db_example

spring.datasource.username=user

spring.datasource.password=ThePassword

自己的application.properties配置文件

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis_jorya?characterEncoding=utf-8&serverTimezone=UTC&useSSL=false
jdbc.username=root
jdbc.password=1234
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

威威猫的栗子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值