很入门的知识,大家了解下就OK

maven配置文件pom:

spring:
datasource:
url: jdbc:mysql://localhost:3306/test
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver  

service层

package com.toov5.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; @Service //注册到Spring 容器中去
public class UserServiceImpl {
@Autowired
private JdbcTemplate jdbcTemplate;
public String createUser(String name, Integer age) {
jdbcTemplate.update("insert into users values(null,?,?);", name, age);
return "success"; }
}

controller

package com.toov5.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import com.toov5.service.UserServiceImpl; @RestController
public class IndexController{ @Autowired
private UserServiceImpl u; @RequestMapping("/index")
public String index(String name, Integer age){
u.createUser(name, age);
return "ok";
} }

启动类:

package com.toov5.service;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication(scanBasePackages={"com.toov5.*"})
public class App { public static void main(String[] args) {
SpringApplication.run(App.class, args);
} }

访问结果:

数据库:

Spring Boot2.0之 整合JDBC的更多相关文章

  1. Spring Boot2.0之整合事物管理

    首先Spring 事务分类 1.声明事务  原理:基于编程事务的 2.编程事务  指定范围 扫包去解决 3.事务原理:AOP技术   通过环绕通知进行了拦截 使用Spring 事务注意事项: 不要tr ...

  2. Spring Boot2.0之整合Mybatis

    我在写这个教程时候,踩了个坑,一下子折腾到了凌晨两点半. 坑: Spring Boot对于Mysql8.1的驱动支持不好啊 我本地安装的是Mysql8.1版本,在开发时候.pom提示不需要输入驱动版本 ...

  3. Spring Boot2.0之整合JSP

    首先不建议整合JSP哈,spring boot 对jsp的支持力度不大.  内置tomcat不支持jsp. 注意:在创建项目时候一定是war类型的,而不是跟之前那个freemarker那种jar类型. ...

  4. Spring Boot2.0之整合多数据源

    一般公司分两个数据库: 一个放共同配置文件, 一个数据库垂直业务数据库 垂直拆分和水平拆分: 垂直是根据业务划分具体数据库 在一个项目中有多个数据源(不同库jdbc) 无限个的哈~ 根据包名 或者 注 ...

  5. Spring Boot2.0之 整合XXL-Job

    参考git上面的 springboot demo 创建maven工程: pom: <project xmlns="http://maven.apache.org/POM/4.0.0&q ...

  6. Spring Boot2.0之 整合Zookeeper集群

    普通的连接: pom: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://w ...

  7. Spring Boot2.0之 整合Redis集群

    项目目录结构: pom: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:// ...

  8. Spring Boot2.0之 整合Redis事务

    Redis事物 Redis 事务可以一次执行多个命令, 并且带有以下两个重要的保证: 事务是一个单独的隔离操作:事务中的所有命令都会序列化.按顺序地执行.事务在执行的过程中,不会被其他客户端发送来的命 ...

  9. Spring Boot2.0之整合Redis

    需要的maven依赖 jar包,是对Jedis的封装 maven依赖: <project xmlns="http://maven.apache.org/POM/4.0.0" ...

随机推荐

  1. API接口管理工具postman等

    国外 postman Swagger:国外比较流行的一款管理工具,英文配置,需要一定的英文基础和服务器搭建基础,学习成本较高. 国内 Apizza: 风格类似postman,熟悉postman的会比较 ...

  2. 25. Spring Boot使用自定义的properties【从零开始学Spring Boot】

    转:http://blog.csdn.net/linxingliang/article/details/52069515 spring boot使用application.properties默认了很 ...

  3. 手动脱Mole Box壳实战总结

    作者:Fly2015 这个程序是吾爱破解脱壳练习第8期的加壳程序,该程序的壳是MoleBox V2.6.5壳,这些都是广告,能够直接无视了.前面的博客手动脱Mole Box V2.6.5壳实战中已经给 ...

  4. tp框架where条件查询数据库

    tp框架where条件查询数据库 Where 条件表达式格式为: $map['字段名'] = array('表达式', '操作条件'); 其中 $map 是一个普通的数组变量,可以根据自己需求而命名. ...

  5. C# 调用API接口处理公共类 自带JSON实体互转类

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...

  6. iOS - 贝塞尔曲线,折线,曲线,波浪线

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZHlsYW5fbHdiXw==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  7. shell脚本实现定时重启任务并输出日志信息

    #!/bin/bash #当前日期 time=`date` pidno=`ps aux|grep adserver-beta|grep -v "grep"|awk '{print ...

  8. 检验 java 基础数据类型参数传递方式

    测试证明,java基础数据类型参数传递值虽是引用传递但是值不会改变.对象是引用传递,值会改变. 为什么?找到一段话来解释这个问题. "对于字符串对象来说,虽然在参数传递的时候也是引用传递,但 ...

  9. 利用DataSet部分功能实现网站登录

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  10. Battery Charging Specification 1.2 中文详解

    转:       http://blog.csdn.net/liglei/article/details/228 1. Introduction 1.1 Scope 规范定义了设备通过USB端口充电的 ...