springboot: 集成jdbc
1.pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.lf</groupId>
<artifactId>SpringBoot_Jdbc</artifactId>
<version>0.0.1-SNAPSHOT</version> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies> </project>
2.service
package com.lf.service.impl; import java.util.ArrayList;
import java.util.List;
import java.util.Map; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import com.lf.service.UserService; @Service("userService")
public class UserServiceImpl implements UserService {
@Autowired
private JdbcTemplate jdbcTemplate; public List<Map<String, Object>> queryUser() {
List<Map<String, Object>> queryForList = new ArrayList<Map<String,Object>>();
try {
queryForList = jdbcTemplate.queryForList("select * from t_user");
} catch (Exception e) {
e.printStackTrace();
}
return queryForList;
} }
3.controller
package com.lf.controller; import java.util.List;
import java.util.Map; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import com.lf.service.UserService; @RestController
public class UserController {
@Autowired
private UserService userService; @RequestMapping("queryUser")
public String queryUser(){return userService.queryUser().toString();
} }
4.properties(目录为:/src/main/resources/application.properties,配置文件名称不能是其他的)
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=leifei
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
5.测试

springboot: 集成jdbc的更多相关文章
- SpringBoot 2.X集成 jdbc自动配置原理探究
前言 Springboot对于数据访问层,不管是 SQL还是 NOSQL,Spring Boot 底层都是采用 Spring Data 的方式统一处理.Spring Data 是 Spring 家族中 ...
- springboot集成mybatis(二)
上篇文章<springboot集成mybatis(一)>介绍了SpringBoot集成MyBatis注解版.本文还是使用上篇中的案例,咱们换个姿势来一遍^_^ 二.MyBatis配置版(X ...
- springboot集成mybatis(一)
MyBatis简介 MyBatis本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation迁移到了google code,并且改名为MyB ...
- springboot集成redis(mybatis、分布式session)
安装Redis请参考:<CentOS快速安装Redis> 一.springboot集成redis并实现DB与缓存同步 1.添加redis及数据库相关依赖(pom.xml) <depe ...
- 基于Springboot集成security、oauth2实现认证鉴权、资源管理
1.Oauth2简介 OAuth(开放授权)是一个开放标准,允许用户授权第三方移动应用访问他们存储在另外的服务提供者上的信息,而不需要将用户名和密码提供给第三方移动应用或分享他们数据的所有内容,OAu ...
- SpringBoot 集成Mybatis 连接Mysql数据库
记录SpringBoot 集成Mybatis 连接数据库 防止后面忘记 1.添加Mybatis和Mysql依赖 <dependency> <groupId>org.mybati ...
- SpringBoot Druid整合,SpringBoot 集成Druid
SpringBoot Druid整合,SpringBoot 集成Druid ================================ ©Copyright 蕃薯耀 2018年4月8日 http ...
- SpringBoot集成TkMybatis插件
前提: 基于SpringBoot项目,正常集成Mybatis后,为了简化sql语句的编写,甚至达到无mapper.xml文件. 在本篇总结教程,不在进行SpringBoot集成Mybatis的概述. ...
- springboot自定义jdbc操作库+基于注解切点AOP
发布时间:2018-11-08 技术:springboot+aop 概述 springBoot集成了自定义的jdbc操作类及AOP,因为spring自带的JdbcTemplate在实际项目中并 ...
随机推荐
- Sql Server 2008 清理日志文件
Use LingZhong Select NAME,size From sys.database_files ALTER DATABASE LingZhong SET RECOVERY SIMPLE ...
- javascript的几种使用多行字符串的方式
JS里并没有标准的多行字符串的表示方法,但是在用模板的时候,为了保证模板的可阅读性,我们又不可避免的使用多行字符串,所以出现了各种搞法,这里以一段jade的模板作为示例,简单总结和对比一下. 字符串相 ...
- 4666 Hyperspace stl
当时自己做的时候没有这么想,想的是每个象限去找一个无穷值来作为比较点.但是很麻烦 代码: #include <stdio.h> #include <string.h> #inc ...
- 初次安装git配置用户名和邮箱及密钥
在Windows上安装Git: 在Windows上使用Git,可以从Git官网直接下载安装程序,(网速慢的同学请移步国内镜像),然后按默认选项安装即可. 安装完成后 键盘敲上:windows+r你会看 ...
- oracle 修改字符集 修改为ZHS16GBK
oracle数据库的字符集更改 A.oracle server 端 字符集查询 select userenv('language') from dual 其中NLS_CHARACTERSET 为ser ...
- 面向对象:三大特性、类成员、property
一.类的基础知识 python 一切皆为对象. 我们以前的str,list,int 都是对象. 1.1 类的定义 与 调用 class 关键字用来定义类,注意类名首字母大写. 类的调用,先实例化一个类 ...
- Algorithm4.子数组求和贪心
子数组求和最大问题 20131011 问题描述 一个数组中,有整数也有复数,求这个数组的所有子数组中,求和最大的值. 这是一个动态规划问题,乍看上去没有什么简单的方法,把所有的情况列出来就可以了,但是 ...
- 【网络编程】inet_addr、inet_ntoa、inet_aton、inet_ntop和inet_pton区分
先上一张图 1.把ip地址转化为用于网络传输的二进制数值 int inet_aton(const char *cp, struct in_addr *inp); inet_aton() 转换网络主机地 ...
- 使用游标、存储过程、pivot 三种方法导入数据
--使用游标循环 if (exists (select * from sys.objects where name = 'Base_RecordTend_Test')) drop proc Base_ ...
- LeetCode OJ:Word Pattern(单词模式)
Given a pattern and a string str, find if str follows the same pattern. Here follow means a full mat ...