插入一个小篇章,有人在编写代码的时候,要么控制台乱码,要么页面乱码等等,

我这里有个配置,可以解决各种乱码问题,直接来看。

# ==================== 编码配置 ====================
spring.banner.charset=UTF-8
server.tomcat.uri-encoding=UTF-8
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
spring.messages.encoding=UTF-8

后边有需要的话,还会补充其他需要的配置。

顺便,把近期用到的entity和dao文件都更新到这里,自取:(直接复制的童鞋,自己加package)

import java.util.Date;

public class Employee {

    private Integer id;
private String lastName; private String email;
//1 male, 0 female
private Integer gender;
private Department department;
private Date birth; public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getLastName() {
return lastName;
} public void setLastName(String lastName) {
this.lastName = lastName;
} public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
} public Integer getGender() {
return gender;
} public void setGender(Integer gender) {
this.gender = gender;
} public Department getDepartment() {
return department;
} public void setDepartment(Department department) {
this.department = department;
} public Date getBirth() {
return birth;
} public void setBirth(Date birth) {
this.birth = birth;
}
public Employee(Integer id, String lastName, String email, Integer gender,
Department department) {
super();
this.id = id;
this.lastName = lastName;
this.email = email;
this.gender = gender;
this.department = department;
this.birth = new Date();
} public Employee() {
} @Override
public String toString() {
return "Employee{" +
"id=" + id +
", lastName='" + lastName + '\'' +
", email='" + email + '\'' +
", gender=" + gender +
", department=" + department +
", birth=" + birth +
'}';
} }

Employee

public class Department {

    private Integer id;
private String departmentName; public Department() {
} public Department(int i, String string) {
this.id = i;
this.departmentName = string;
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getDepartmentName() {
return departmentName;
} public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
} @Override
public String toString() {
return "Department [id=" + id + ", departmentName=" + departmentName + "]";
} }

Department

@Repository
public class EmployeeDao { private static Map<Integer, Employee> employees = null; @Autowired
private DepartmentDao departmentDao; static {
employees = new HashMap<Integer, Employee>(); employees.put(1001, new Employee(1001, "E-AA", "aa@163.com", 1, new Department(101, "D-AA")));
employees.put(1002, new Employee(1002, "E-BB", "bb@163.com", 1, new Department(102, "D-BB")));
employees.put(1003, new Employee(1003, "E-CC", "cc@163.com", 0, new Department(103, "D-CC")));
employees.put(1004, new Employee(1004, "E-DD", "dd@163.com", 0, new Department(104, "D-DD")));
employees.put(1005, new Employee(1005, "E-EE", "ee@163.com", 1, new Department(105, "D-EE")));
} private static Integer initId = 1006; public void save(Employee employee) {
if (employee.getId() == null) {
employee.setId(initId++);
} employee.setDepartment(departmentDao.getDepartment(employee.getDepartment().getId()));
employees.put(employee.getId(), employee);
} // 查询所有员工
public Collection<Employee> getAll() {
return employees.values();
} public Employee get(Integer id) {
return employees.get(id);
} public void delete(Integer id) {
employees.remove(id);
}
}

EmployeeDao

import java.util.Collection;
import java.util.HashMap;
import java.util.Map; import com.iceodin.model.Department;
import org.springframework.stereotype.Repository; @Repository
public class DepartmentDao { private static Map<Integer, Department> departments = null; static{
departments = new HashMap<Integer, Department>(); departments.put(101, new Department(101, "D-AA"));
departments.put(102, new Department(102, "D-BB"));
departments.put(103, new Department(103, "D-CC"));
departments.put(104, new Department(104, "D-DD"));
departments.put(105, new Department(105, "D-EE"));
} public Collection<Department> getDepartments(){
return departments.values();
} public Department getDepartment(Integer id){
return departments.get(id);
} }

DepartmentDao

SpringBoot日记——编码配置篇的更多相关文章

  1. SpringBoot日记——Web开发篇

    准备开始实战啦!~~~~ 我们先来看,SpringBoot的web是如何做web开发的呢?通常的步骤如下: 1.创建springboot应用,指定模块: 2.配置部分参数配置: 3.编写业务代码: 为 ...

  2. SpringBoot日记——日志框架篇

    在项目的开发中,日志是必不可少的一个记录事件的组件,所以也会相应的在项目中实现和构建我们所需要的日志框架. 而市面上常见的日志框架有很多,比如:JCL.SLF4J.Jboss-logging.jUL. ...

  3. SpringBoot日记——Cache缓存篇

    通常我们访问数据的情况如下图,数据存缓存就取缓存,不存缓存就取数据库,这样可以提升效率,不用一直读取数据库的信息: 开始记录: 关于SpringBoot缓存的应用 1. 首先在pom.xml文件中添加 ...

  4. Springboot日记——核心编码篇

    背景吐槽:想要让自己进阶一下,一定要有个可以拿出来秀的东西,所以要尝试写一个属于自己的网站或者平台.因此,我大概的看了一下springboot+Mybatis-plus+... 框架介绍 通常 SSM ...

  5. SpringBoot系列教程web篇之404、500异常页面配置

    接着前面几篇web处理请求的博文,本文将说明,当出现异常的场景下,如404请求url不存在,,403无权,500服务器异常时,我们可以如何处理 原文友链: SpringBoot系列教程web篇之404 ...

  6. Linux配置mysql (centos配置java环境 mysql配置篇 总结四)

    ♣安装的几种方法和比较 ♣配置yum源 ♣安装mysql ♣启动mysql ♣修改密码 ♣导入.sql文件 ♣缓存设置 ♣允许远程登录(navicat) ♣配置编码为utf8  1.关于Linux系统 ...

  7. SpringBoot之旅第一篇-初探

    一.SpringBoot是什么? 微服务,应该是近年来最火的概念,越来越多的公司开始使用微服务架构,面试中被问到的微服务的概率很高,不管对技术的追求,还是为了进更好的公司,微服务都是我们开发人员的必须 ...

  8. SpringBoot的自动配置

    1.根据条件来装配bean,SpringBoot的自动配置,根据条件进行自动配置. 首先创建一个接口,如下所示: package com.bie.encoding; /** * * @Descript ...

  9. SpringBoot入门(IDEA篇)(一)

    一.SpringBoot简介 开发团队:Pivotal团队 主要目的:简化新Spring应用的初始搭建以及开发过程. 秉持理念:约定优于配置.(该框架使用了特定的方式来进行配置,从而使开发人员不再需要 ...

随机推荐

  1. supervisor 使用系列之一

    supervisor 使用系列之一 前几年自己用PHP写过一个服务守护的脚本,初步实现了被守护脚本的状态监控.优雅杀死.以及自动重启的功能.面试的时候也有问到,为什么不使用supervisor这个工具 ...

  2. 用apiDoc简化接口开发

    身为程序员最讨厌看到的代码没有注释,自己的代码却讨厌写注释,觉得麻烦,接口也是这样. 比如公司要做一个H5活动的页面,开发文档已经发到后端开发.设计.与前端的邮箱了,其实这个时候就可以开始开发了.开发 ...

  3. MySQL基础之 AND和OR运算符

    AND和OR运算符 作用:用于基于一个以上的条件对记录进行过滤 用法:可在WHERE子句中把两个或多个条件结合在一起. AND:如果第一个条件和第二个条件都成立,才会显示一条记录 OR:如果第一个条件 ...

  4. 通过sqli-labs学习sql注入——基础挑战之less1-3

    首先,先看一些基础知识吧!!!!本人只是初学者,记录一下自己的学习过程,有什么错误之处请指出,谢谢!大佬请绕过!!!! url编码:一般的url编码其实就是那个字符的ASCII值得十六进制,再在前面加 ...

  5. vc获取当前进程CPU使用率

    double GetCPUUserRate() { HANDLE hProcess=::GetCurrentProcess(); static DWORD s_dwTickCountOld = 0; ...

  6. Django商城项目笔记No.11用户部分-QQ登录1获取QQ登录网址

    Django商城项目笔记No.11用户部分-QQ登录 QQ登录,亦即我们所说的第三方登录,是指用户可以不在本项目中输入密码,而直接通过第三方的验证,成功登录本项目. 若想实现QQ登录,需要成为QQ互联 ...

  7. Spring 加载Controller逻辑的源码笔记

    org.springframework.web.servlet.handler.AbstractHandlerMethodMapping#initHandlerMethods 进行加载Controll ...

  8. MetaMask/json-rpc-engine

    https://github.com/MetaMask/json-rpc-engine RpcEngine——MetaMask/json-rpc-engine https://github.com/M ...

  9. linux ssh 应用

    linux 服务器 连接另一个linux服务器 ssh 用户名@IP地址 linux 服务器传输文件到另一个linux服务器 scp 文件名(可多个)  用户名@IP地址:传到的目录 /home

  10. 21天,搞定软件测试从业者必备的Linux命令

    开始之前,先同步一个结论: 对于软件测试从业者,如果你至今为止,还不懂Linux,或者完全没有接触Linux ,这是一件很危险和恐怖的事 . 此刻.现在.果断,学习Linux命令 . 如果你工作中,完 ...