1.属性配置文件(application.properties)

    # type 可以修改连接池类型,默认采用Tomcat的连接池
# spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.url=jdbc:mysql://localhost:3306/consult
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=org.gjt.mm.mysql.Driver

2.pom.xml 配置maven依赖

    <!-- MYSQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- Spring Boot JDBC -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

3.Java查询示例

 import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
/**
* service层
*/
@Service
public class CommonServiceImpl implements CommonService { // 注入JdbcTemplate
@Autowired
private JdbcTemplate jdbcTemplate; public List<ConsultContent> queryContent(Map map) {
String sql = "select * from consult_content a where a.state = 0 and a.type = 1 order by a.itemindex";
return jdbcTemplate.query(sql, new RowMapper<ConsultContent>() { public ConsultContent mapRow(ResultSet rs, int rowNum)
throws SQLException {
ConsultContent cc = new ConsultContent();
cc.setContent(rs.getString("content"));
cc.setId(rs.getInt("id"));
cc.setItemIndex(rs.getInt("itemIndex"));
cc.setState(rs.getInt("state"));
cc.setType(rs.getString("type"));
return cc;
}
});
}
}

SpringBoot(九)-- SpringBoot JDBC的更多相关文章

  1. SpringBoot(九) -- SpringBoot与数据访问

    一.简介 对于数据访问层,无论是SQL还是NOSQL,Spring Boot默认采用整合Spring Data的方式进行统一处理,添加大量自动配置,屏蔽了很多设置.引入各种xxxTemplate,xx ...

  2. SpringBoot(九):SpringBoot集成Mybatis

    (1)新建一个SpringBoot工程,在pom.xml中配置相关jar依赖 贴代码: <!--加载mybatis整合springboot--> <dependency> &l ...

  3. SpringBoot系列之JDBC数据访问

    SpringBoot系列之JDBC数据访问 New->Project or Module->Spring Initializer 选择JDBC和mysql驱动,为了方便测试web等等也可以 ...

  4. springcloud(九) springboot Actuator + admin 监控

    前一章讲的都是Feign项目(调用方)的监控.接下来讲的是服务提供方的监控 一.springboot actuator + springboot admin Spring Boot Admin 是一个 ...

  5. 【SpringBoot】SpringBoot配置与单元测试(二)

    SpringBoot项目创建参考[SpringBoot]SpringBoot快速入门(一) 本文介绍SpringBoot项目的POM文件.配置与单元测试 POM文件 1.SpringBoot的pom文 ...

  6. SpringBoot(七)-SpringBoot JPA-Hibernate

    步骤 1.在pom.xml添加mysql,spring-data-jpa依赖2.在application.properties文件中配置mysql连接配置文件3.在application.proper ...

  7. 【SpringBoot】SpringBoot 入门示例

    参考资料: http://www.tuicool.com/articles/mqeee2A http://www.cnblogs.com/suncj/p/4065589.html http://spr ...

  8. springBoot系列-->springBoot注解大全

    一.注解(annotations)列表 @SpringBootApplication:包含了@ComponentScan.@Configuration和@EnableAutoConfiguration ...

  9. [SpringBoot] - 了解什么是SpringBoot,使用SpringBoot的配置文件

    首先明白Spring是什么,Spring是Java开发的一个框架,为了方便简化Java开发. 什么是注解(注解式开发)? Spring的常用注解有哪些? 假如用SpringBoot构建一个网站程序,应 ...

  10. Springboot】Springboot整合邮件服务(HTML/附件/模板-QQ、网易)

    介绍 邮件服务是常用的服务之一,作用很多,对外可以给用户发送活动.营销广告等:对内可以发送系统监控报告与告警. 本文将介绍Springboot如何整合邮件服务,并给出不同邮件服务商的整合配置. 如图所 ...

随机推荐

  1. android 代码混淆模板

    #指定代码的压缩级别 -optimizationpasses #包明不混合大小写 -dontusemixedcaseclassnames #不去忽略非公共的库类 -dontskipnonpublicl ...

  2. 让网站和APP更具动感的几点建议

    [编者按]本文来自Smashing Magazine,作者为Brolik的联合创始人.首席创意官Drew Thomas.文中介绍了Web中增加动感设计可带来的好处及进行动感设计的几点建议,如采用图层技 ...

  3. iOS 基础入门--Bull' Eye 小游戏 

      说明   Bull's Eye小游戏是http://www.raywenderlich.com/store/ios-apprentice里非常酷的入门demo 跟着该教程一步步做下来便有了 ...

  4. github开源库(三)

    41.android-swipelistview SwipeListView是一个Android List View实现,实现了自定义ListView单元格,可通过滑动来显示扩展面板.开发者可直接登陆 ...

  5. Self20171218_TestNG+Maven+IDEA环境搭建

    前言: 主要进行TestNG测试环境的搭建 所需环境: 1.IDEA UItimate 2.JDK 3.Maven 一.创建工程 File –>new –>Project–>next ...

  6. WM_CONCAT字符超过4000的处理办法

    参考网址: http://stackoverflow.com/questions/11541383/ordering-by-list-of-strings-in-oracle-sql-without- ...

  7. Linux C语言连接 sqlserver数据库

    记录一下Linux下使用C语言连接sqlserver的方法. 连接前需要安装freetds. 参考: http://www.cnblogs.com/helloworldtoyou/p/6910075. ...

  8. iOS开发OC基础:Xcode中常见英文总结,OC常见英文错误

    在开发的过程中难免会遇到很多的错误,可是当看到系统给出的英文时,又不知道是什么意思.所以这篇文章总结了Xcode中常见的一些英文单词及词组,可以帮助初学的人快速了解给出的提示.多练习,就肯定能基本掌握 ...

  9. (原)linux下利用cmake来编译jthread开源库

    其实上次在用hisi3531平台的时候,就已经编译过一次这个库了,这次换了平台环境,交叉编译器变成了arm-hisiv100-linux-工具链,所以,没办法只能重新来过. 因为之前编译过,所以这次还 ...

  10. VS2013 此模板尝试加载组件程序集”NuGet.VisualStudio.interop,Version=1.0.0.0 的解决办法

    此模板尝试加载组件程序集 NuGet.VisualStudio.Interop   分析错误 既然错误信息提示模板尝试加载组件程序集,那说明NuGet.VisualStudio.Interop程序集不 ...