Springboot日记——核心编码篇
背景吐槽:想要让自己进阶一下,一定要有个可以拿出来秀的东西,所以要尝试写一个属于自己的网站或者平台。因此,我大概的看了一下springboot+Mybatis-plus+...
框架介绍
通常 SSM(Spring+SpringMVC+MyBatis)框架集由Spring、SpringMVC、MyBatis三个开源框架整合而成,常作为数据源较简单的web项目的框架。
框架构成-1:核心及运行代码

框架配置-2:参数配置

框架学习,随笔记录
1 Application运行类编写:
@SpringBootApplication
public class Application{
public static void main(String[] args){
SpringApplication.run(Application.class,args);
}
}
2 Controller类的编写:
@Controller
public class UserController {
@GetMapping("/test")
@ResponseBody
public String test(){
return “hello springboot”
}
}
3 Entity类(model/Pojo)编写:
@Component
public class user(){
private String name;
private Integer age; //getter/setter/tostring
}
4 配置文件,SpringBoot允许使用properties文件,yaml文件,和命令参数作为外部配置,
4.1 常规配置-命名默认application.yml (属性和参数间有空格)
server:
port: 8081
user:
name: 瓦尔克莉
age: 22
以上配置,可以在Entity/model的类中添加注解来获取如:
@ConfigurationProperties(prefix = "user")
@Component
public class User { private String name;
private Integer age; }
然后修改controller类来实体化这个类并获取数据
@Controller
public class UserController {
@Autowired // 实体化
private User user; @GetMapping("/test") //通过ip:port/test访问该信息
@ResponseBody
public String test(){
return “我叫”+user.getName()+"今年"+user.getAge()+“岁”
}
}
运行结果 :
4.2 命令行运行,springboot基于jar运行,若需要修改运行接口,如下:
java -jar XXX.jar --server.port=9090
4.3 使用xml配置,虽然不太喜欢用,但是有些时候还是要的
@ImportResource({"classpath:some-content.xml","classpath:another-content.xml"})
4.4 日志配置,SpringBoot支持java Util Logging,Log4j,Log4j2和Logback等作为日志框架,且默认使用Logback(我觉得默认的就OK)
# 日志输出路径
logging.path=output/logs/
# 日志输出级别 logging.level.包名=xx
logging.level.xx=debug
Springboot日记——核心编码篇的更多相关文章
- SpringBoot日记——Web开发篇
准备开始实战啦!~~~~ 我们先来看,SpringBoot的web是如何做web开发的呢?通常的步骤如下: 1.创建springboot应用,指定模块: 2.配置部分参数配置: 3.编写业务代码: 为 ...
- SpringBoot日记——日志框架篇
在项目的开发中,日志是必不可少的一个记录事件的组件,所以也会相应的在项目中实现和构建我们所需要的日志框架. 而市面上常见的日志框架有很多,比如:JCL.SLF4J.Jboss-logging.jUL. ...
- SpringBoot日记——Cache缓存篇
通常我们访问数据的情况如下图,数据存缓存就取缓存,不存缓存就取数据库,这样可以提升效率,不用一直读取数据库的信息: 开始记录: 关于SpringBoot缓存的应用 1. 首先在pom.xml文件中添加 ...
- 源码学习系列之SpringBoot自动配置(篇二)
源码学习系列之SpringBoot自动配置(篇二)之HttpEncodingAutoConfiguration 源码分析 继上一篇博客源码学习系列之SpringBoot自动配置(篇一)之后,本博客继续 ...
- SpringBoot系列教程web篇之自定义异常处理HandlerExceptionResolver
关于Web应用的全局异常处理,上一篇介绍了ControllerAdvice结合@ExceptionHandler的方式来实现web应用的全局异常管理: 本篇博文则带来另外一种并不常见的使用方式,通过实 ...
- springboot中的编码设置
在springboot中编码配置可以通过filter也可以通过springboot的核心配置文件application.properties中配置如下信息: #配置字符编码spring.http.en ...
- Zend Framework学习日记(2)--HelloWorld篇(转)
Zend Framework学习日记(2)--HelloWorld篇 这一篇主要演示如何用zf命令行工具建立一个基于Zend Framework框架的工程,也是我初学Zend Framework的小练 ...
- SpringBoot学习(五)-->SpringBoot的核心
SpringBoot的核心 1.入口类和@SpringBootApplication Spring Boot的项目一般都会有*Application的入口类,入口类中会有main方法,这是一个标准的J ...
- SpringBootTest单元测试实战、SpringBoot测试进阶高级篇之MockMvc讲解
1.@SpringBootTest单元测试实战 简介:讲解SpringBoot的单元测试 1.引入相关依赖 <!--springboot程序测试依赖,如果是自动创建项目默认添加--> &l ...
随机推荐
- oracle 启动报错ORA-27125解决方案
脚本: oracle@edwdb:~> id uid=(oracle) gid=(oinstall) (oinstall),(dba) oracle@edwdb:~> su - root ...
- SQL Server错误处理
一.SQLServer数据库引擎错误 1.查询系统错误信息 SQLServer在每个数据库的系统视图sys.messages中存储系统自定义(Message_id <= 50000)和用户自定义 ...
- Service Mesh服务网格之Linkerd架构
今天详细介绍一下Linkerd的架构. 控制平面 Linkerd控制平面是一组在专用Kubernetes命名空间中运行的服务(在Linked默认情况下).这些服务完成各种事情——聚合遥测数据.提供面向 ...
- C#调取webapi
//定义参数 C#调取webapi var content = new FormUrlEncodedContent(new Dictionary<string, string>() { { ...
- linux 字体 设置 en_US.UTF-8
设置:localectl set-local LANG=en_US.UTF-8 查看: localectl list-locales
- 集合之LinkedList
一.概述 LinkedList与ArrayList一样实现List接口,只是ArrayList是List接口的大小可变数组的实现,LinkedList是List接口链表的实现.基于链表实现的方式使得L ...
- vs未能正确加载XXX包,编译时停止工作问题
出现这个问题的原因可能是配置更改或安装了另一个扩展,幸好之前用的不多,重新进行用户配置代价也不高,打开Visual Studio Tools: 选择VS2013 开发人员命令提示: 输入deven ...
- utf-8 转码--网址转码
NSString *name = @"联通测试"; NSString *utfName = [name stringByAddingPercentEncodingWithAllow ...
- ZOJ 2476 Total Amount 字符串模拟
- Total Amount Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit ...
- 学习笔记——OS——引论
学习笔记--OS--引论 操作系统的定义 操作系统是一组管理计算机硬件资源的软件集合: 用户和计算机硬件之间的接口 控制和管理硬件资源 实现对计算机资源的抽象 计算机系统硬件 冯诺依曼体系结构和哈佛结 ...