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

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

  1. # ==================== 编码配置 ====================
  2. spring.banner.charset=UTF-8
  3. server.tomcat.uri-encoding=UTF-8
  4. spring.http.encoding.charset=UTF-8
  5. spring.http.encoding.enabled=true
  6. spring.http.encoding.force=true
  7. spring.messages.encoding=UTF-8

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

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

  1. import java.util.Date;
  2.  
  3. public class Employee {
  4.  
  5. private Integer id;
  6. private String lastName;
  7.  
  8. private String email;
  9. //1 male, 0 female
  10. private Integer gender;
  11. private Department department;
  12. private Date birth;
  13.  
  14. public Integer getId() {
  15. return id;
  16. }
  17.  
  18. public void setId(Integer id) {
  19. this.id = id;
  20. }
  21.  
  22. public String getLastName() {
  23. return lastName;
  24. }
  25.  
  26. public void setLastName(String lastName) {
  27. this.lastName = lastName;
  28. }
  29.  
  30. public String getEmail() {
  31. return email;
  32. }
  33.  
  34. public void setEmail(String email) {
  35. this.email = email;
  36. }
  37.  
  38. public Integer getGender() {
  39. return gender;
  40. }
  41.  
  42. public void setGender(Integer gender) {
  43. this.gender = gender;
  44. }
  45.  
  46. public Department getDepartment() {
  47. return department;
  48. }
  49.  
  50. public void setDepartment(Department department) {
  51. this.department = department;
  52. }
  53.  
  54. public Date getBirth() {
  55. return birth;
  56. }
  57.  
  58. public void setBirth(Date birth) {
  59. this.birth = birth;
  60. }
  61. public Employee(Integer id, String lastName, String email, Integer gender,
  62. Department department) {
  63. super();
  64. this.id = id;
  65. this.lastName = lastName;
  66. this.email = email;
  67. this.gender = gender;
  68. this.department = department;
  69. this.birth = new Date();
  70. }
  71.  
  72. public Employee() {
  73. }
  74.  
  75. @Override
  76. public String toString() {
  77. return "Employee{" +
  78. "id=" + id +
  79. ", lastName='" + lastName + '\'' +
  80. ", email='" + email + '\'' +
  81. ", gender=" + gender +
  82. ", department=" + department +
  83. ", birth=" + birth +
  84. '}';
  85. }
  86.  
  87. }

Employee

  1. public class Department {
  2.  
  3. private Integer id;
  4. private String departmentName;
  5.  
  6. public Department() {
  7. }
  8.  
  9. public Department(int i, String string) {
  10. this.id = i;
  11. this.departmentName = string;
  12. }
  13.  
  14. public Integer getId() {
  15. return id;
  16. }
  17.  
  18. public void setId(Integer id) {
  19. this.id = id;
  20. }
  21.  
  22. public String getDepartmentName() {
  23. return departmentName;
  24. }
  25.  
  26. public void setDepartmentName(String departmentName) {
  27. this.departmentName = departmentName;
  28. }
  29.  
  30. @Override
  31. public String toString() {
  32. return "Department [id=" + id + ", departmentName=" + departmentName + "]";
  33. }
  34.  
  35. }

Department

  1. @Repository
  2. public class EmployeeDao {
  3.  
  4. private static Map<Integer, Employee> employees = null;
  5.  
  6. @Autowired
  7. private DepartmentDao departmentDao;
  8.  
  9. static {
  10. employees = new HashMap<Integer, Employee>();
  11.  
  12. employees.put(1001, new Employee(1001, "E-AA", "aa@163.com", 1, new Department(101, "D-AA")));
  13. employees.put(1002, new Employee(1002, "E-BB", "bb@163.com", 1, new Department(102, "D-BB")));
  14. employees.put(1003, new Employee(1003, "E-CC", "cc@163.com", 0, new Department(103, "D-CC")));
  15. employees.put(1004, new Employee(1004, "E-DD", "dd@163.com", 0, new Department(104, "D-DD")));
  16. employees.put(1005, new Employee(1005, "E-EE", "ee@163.com", 1, new Department(105, "D-EE")));
  17. }
  18.  
  19. private static Integer initId = 1006;
  20.  
  21. public void save(Employee employee) {
  22. if (employee.getId() == null) {
  23. employee.setId(initId++);
  24. }
  25.  
  26. employee.setDepartment(departmentDao.getDepartment(employee.getDepartment().getId()));
  27. employees.put(employee.getId(), employee);
  28. }
  29.  
  30. // 查询所有员工
  31. public Collection<Employee> getAll() {
  32. return employees.values();
  33. }
  34.  
  35. public Employee get(Integer id) {
  36. return employees.get(id);
  37. }
  38.  
  39. public void delete(Integer id) {
  40. employees.remove(id);
  41. }
  42. }

EmployeeDao

  1. import java.util.Collection;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4.  
  5. import com.iceodin.model.Department;
  6. import org.springframework.stereotype.Repository;
  7.  
  8. @Repository
  9. public class DepartmentDao {
  10.  
  11. private static Map<Integer, Department> departments = null;
  12.  
  13. static{
  14. departments = new HashMap<Integer, Department>();
  15.  
  16. departments.put(101, new Department(101, "D-AA"));
  17. departments.put(102, new Department(102, "D-BB"));
  18. departments.put(103, new Department(103, "D-CC"));
  19. departments.put(104, new Department(104, "D-DD"));
  20. departments.put(105, new Department(105, "D-EE"));
  21. }
  22.  
  23. public Collection<Department> getDepartments(){
  24. return departments.values();
  25. }
  26.  
  27. public Department getDepartment(Integer id){
  28. return departments.get(id);
  29. }
  30.  
  31. }

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. SQL Server 跨网段(跨机房)通过备份文件初始化复制

    笔者最近碰到了需要搭建跨网段的SQL Server复制,实际的拓扑结构如下草图所示: 发布端A服务器位于CDC机房中 订阅端B服务器位于阿里云 因为SQL Server复制不支持通过IP连接分发服务器 ...

  2. MVC 上传下载

    在Asp.net的WEBform中,上传文件与下载文件处理是很简单的事情,如果转为ASP.NET MVC呢?那就没有那么容易了,难少少,也不是很难,一起来看下本文吧.本文主要讲如何在Asp.net M ...

  3. S5700的Eth-Trunk端口汇聚(trunk实验)

    S5700的Eth-Trunk端口汇聚 链路汇聚和端口汇聚,就是端口聚合,交换机的堆叠是堆叠和端口聚合无关. 端口聚合概念:(包括二层端口聚合和三层端口聚合) 1.端口聚合IEEE标准是将最多16条链 ...

  4. c语言:复合文字

    复合文字的意义,相当于是在C语言中,为数组类型定义了一种类似于8之于int,'w'之于char一样的常量类型,所以从C99之后,可以在一些地方使用复合文字来代替数组使用. 复合文字的声明 (]){,, ...

  5. 【排序算法】选择排序(Selection sort)

    0. 说明 选择排序(Selection sort)是一种简单直观的排序算法. 它的工作原理如下. 首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最 ...

  6. MySQL基础值 存储过程和函数

    一.创建存储过程和函数 什么是创建存储过程和函数? 就是将经常使用的一组SQL语句组合在一起,并将这些SQL语句当做一个整体存储在MYSQL服务器中. 创建存储过程的语句是:CREATE  PROCE ...

  7. DevExpress07、DataNavigator、 ControlNavigator

    https://documentation.devexpress.com/WindowsForms/DevExpress.XtraEditors.DataNavigator.class 1.DataN ...

  8. Dubbo -- 系统学习 笔记 -- 安装手册

    安装手册 示例提供者安装 示例消费者安装 Zookeeper注册中心安装 Redis注册中心安装 简易注册中心安装 简易监控中心安装 管理控制台安装 推荐使用Zookeeper注册中心 你可以只运行D ...

  9. 使用filter对请求设置编码

    一.复习 加强方法: 1)继承 2)装饰模式 3)动态代理. 使用装饰模式: 1)要求装饰者和被装饰者实现同一个接口或者继承同一个类. 2)装饰者要求被装饰者的引用. 3)对于要加强的方法进行加强,对 ...

  10. Android源代码下载以及异常查找网站推荐

    源代码下载:https://github.com/ 异常查找:http://stackoverflow.com/