hand-springboot-01&02

关于springboot的简化部署

pom文件中增加插件,可以将应用打包成一个jar包

 

关于获取配置文件的值

如果说,我们只是在某个业务逻辑中需要获取一下配置文件中的某项值,使用@Value;

如果说,我们专门编写了一个javaBean来和配置文件进行映射,我们就直接使用@ConfigurationProperties;

使用 ${}读取配置文件中的内容

使用 #{}是计算括号中的内容,然后赋值

 

 关于profile

Profile是Spring对不同环境提供不同配置功能的支持,可以通过激活、指定参数等方式快速切换环境

1、多profile模式

格式: application-{profile}.properties/yml:

格式: application-dev.properties 、  application-prod.properties

关于日志级别

控制台输出的类型是 warn 和 error 的日志,trace和debug没有输出

日志输出格式说明

 时间 - 线程 - 级别 - logger名字 - 日志信息

 

 Druid是Java语言中最好的数据库连接池,能够提供强大的监控和扩展功能。

springboot整合 PageHelper的分页

spring-boot-starter的版本和PageHelper版本有一定的影响

 注意在使用thymeleaf进行页面跳转的时候,controller层不要写成@RestController,也不要添加上@ResponseBody因为这两个注解都将返回的信息以json的格式呈现。return "list" 那么在前台页面显示的就是list。应该使用@Controller注解

这里提供一个简单的分页页面展示

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<div align="center">
  <table border="1">
    <tr>
      <th>id</th>
      <th>name</th>
    </tr>
    <tr th:each="department:${pageInfo.list}">
      <td th:text="${department.deptNo}"></td>
      <td th:text="${department.deptName}"></td>
    </tr>
  </table>
  <p>当前 <span th:text="${pageInfo.pageNum}"></span> 页,总 <span th:text="${pageInfo.pages}"></span> 页,共 <span th:text="${pageInfo.total}"></span> 条记录</p>
  <a th:href="@{/getAllDepartment}">首页</a>
  <a th:href="@{/getAllDepartment(pageNum=${pageInfo.hasPreviousPage}?${pageInfo.prePage}:1)}">上一页</a>
  <a th:href="@{/getAllDepartment(pageNum=${pageInfo.hasNextPage}?${pageInfo.nextPage}:${pageInfo.pages})}">下一页</a>
  <a th:href="@{/getAllDepartment(pageNum=${pageInfo.pages})}">尾页</a>
</div>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/awodwde/article/details/118757441