Springboot項目學習筆記(二)(1.5-2.0---shangguigu)

 

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   

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章