Springboot日志
引依赖,创建springbootweb项目
模板引擎
语法
@语法引入路径的好处
国际化
配置国际化
使用国际化
登录拦截
1,清缓存步骤
1,禁用模板引擎缓存
2.重新编译按 ctrl+f9
请求转发
给出提示错误消息
排除,使其可以访问
从session中取值
restful风格crud
实验请求
处理员工的controller
处理员工请求的dao
抽取公共页面
三种引入效果
直接写的都是引入可以不用~{}这些符号(使用模板名加片段名)
直接这样写
格式化时间
添加按钮
添加部门员工
在写controller
日期格式化
修改页面页面
、
删除
springboot错误机制
定制错误页面
嵌入式servlet容器定制
配置jdbc,druid数据源
测试
添加druid配置类
整合mybatis
注解版mapper
controller实现
集成jpa
package com.gds.demo.bean;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/**
* @Author 龚道松
* @Date 2019/7/17 16:48
* @Version 1.0
**/
@Entity
public class User {
private Integer id;
private String username;
private String password;
private String name;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", username='" + username + '\'' +
", password='" + password + '\'' +
", name='" + name + '\'' +
'}';
}
}
package com.gds.demo.repository;
import com.gds.demo.bean.User;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* @Author 龚道松
* @Date 2019/7/17 16:53
* @Version 1.0
**/
public interface UserRepository extends JpaRepository<User,Integer> {
public List<User> findAll();
}
# jpa 配置
jpa:
database: mysql
show-sql: true
generate-ddl: true
hibernate:
ddl-auto: update
naming:
strategy: org.hibernate.cfg.ImprovedNamingStrategy
package com.gds.demo;
import com.gds.demo.bean.User;
import com.gds.demo.repository.UserRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
/**
* springboot测试类
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DemoApplication.class)
public class DemoApplicationTests {
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Autowired
DataSource dataSource;
@Autowired
private UserRepository userRepository;
@Test
public void contextLoads() throws SQLException {
System.err.println(dataSource.getClass());
Connection connection = dataSource.getConnection();
System.err.println(connection);
connection.close();
}
/**
* jpa 测试
*/
@Test
public void test(){
List<User> all = userRepository.findAll();
System.err.println(all);
}
}
springboot集成redis
测试结果(第一因为没有缓存所以是数据库查询)
案例地址:https://gitee.com/gongdaosong/spring-boot-demo-jpa.git https://gitee.com/gongdaosong/springbootactuator.git https://gitee.com/gongdaosong/springboot-es.git https://gitee.com/gongdaosong/springboot-rabit.git