时间:2021-07-01 10:21:17 帮助过:11人阅读
测试添加的相关类
package com.junlin.druid.Entity; import javax.persistence.*; import java.io.Serializable; @Entity @Table(name="newtable") public class DemoEntity implements Serializable { @Id @GeneratedValue @Column(name="id") private int id; @Column(name="name") private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
package com.junlin.druid.Dao; import com.junlin.druid.Entity.DemoEntity; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; public interface DemoJPA extends JpaRepository<DemoEntity,Integer> { List<DemoEntity> findByName(String name); }
package com.junlin.druid.Controller; import com.junlin.druid.Dao.DemoJPA; import com.junlin.druid.Entity.DemoEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController public class DemoController { @Autowired private DemoJPA demoJPA; @GetMapping("/findName") public Object findEntity(String name){ List<DemoEntity> list = demoJPA.findByName(name); return list; } }
启动项目,访问localhost:8080/druid/,进入登陆页面输入在application.yml配置好的用户和密码(demo中都是root),即可看到监控页面
访问一下我们准备好的接口,执行几次sql查询,在监控页面点看sql监控页面,就能看到我们的sql执行情况
其它相关的配置以及页面相关内容可以参考druid官网文档,地址https://github.com/alibaba/druid/wiki/常见问题
springboot2.x配置druid sql监控
标签:set 代码 ppi cat row integer ace 官网文档 启动