目录

Grade实体类

public class Grade {
private Integer gradeId;
private String gradeName; public Grade(){ } public Grade(Integer gradeId, String gradeName) {
this.gradeId = gradeId;
this.gradeName = gradeName;
} public Grade(String gradeName) {
this.gradeName = gradeName;
} public Integer getGradeId() {
return gradeId;
} public void setGradeId(Integer gradeId) {
this.gradeId = gradeId;
} public String getGradeName() {
return gradeName;
} public void setGradeName(String gradeName) {
this.gradeName = gradeName;
}
}

IGradeDao

import com.boot.entity.Grade;
import java.util.List;
public interface IGradeDao {
public int insertGrade(Grade grade);
public int updateGrade(Grade grade);
public int deleteGrade(Integer id);
public List<Grade> findAll();
}

IGradeDaoImpl

import com.boot.dao.IGradeDao;
import com.boot.entity.Grade;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository; import javax.annotation.Resource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
@Repository
public class IGradeDaoImpl implements IGradeDao {
//导入JDBCTemplate模板
@Resource
private JdbcTemplate jdbcTemplate; @Override
public int insertGrade(Grade grade) {
return jdbcTemplate.update("insert into Grade(GradeName) values(?)",grade.getGradeName());
} @Override
public int updateGrade(Grade grade) {
return jdbcTemplate.update("update Grade set GradeName=? where GradeId=?",grade.getGradeName(),grade.getGradeId());
} @Override
public int deleteGrade(Integer id) {
return jdbcTemplate.update("delete from Grade where GradeId=?",id);
} @Override
public List<Grade> findAll() {
//封装行数据映射
RowMapper<Grade> rowMapper=new RowMapper<Grade>() {
@Override
public Grade mapRow(ResultSet rs, int rowNum) throws SQLException {
Grade grade=new Grade(rs.getInt("GradeId"),rs.getString("GradeName"));
return grade;
}
};
return jdbcTemplate.query("select * from Grade", rowMapper);
}
}

IGradeService

public interface IGradeService {
public int insertGrade(Grade grade);
public int updateGrade(Grade grade);
public int deleteGrade(Integer id);
public List<Grade> findAll();
}

IGradeServiceImpl

@Service("iGradeService")
public class IGradeServiceImpl implements IGradeService {
@Resource
private IGradeDao iGradeDao;
@Override
public int insertGrade(Grade grade) {
return iGradeDao.insertGrade(grade);
} @Override
public int updateGrade(Grade grade) {
return iGradeDao.updateGrade(grade);
} @Override
public int deleteGrade(Integer id) {
return iGradeDao.deleteGrade(id);
} @Override
public List<Grade> findAll() {
return iGradeDao.findAll();
}
}

JDBCTemplateController

@RestController
public class JDBCTemplateController {
@Resource
private IGradeService iGradeService; @RequestMapping("/insertGrade")
public int insertGrade(){
return iGradeService.insertGrade(new Grade("S1"));
}
@RequestMapping("/updateGrade")
public int updateGrade(){
return iGradeService.updateGrade(new Grade(,"S2"));
}
@RequestMapping("/deleteGrade")
public int deleteGrade(){
return iGradeService.deleteGrade();
}
@RequestMapping("/findAll")
public List<Grade> findAll(){
return iGradeService.findAll();
}
}

application.yml

spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql:///springbootjpa
username: root
password: ##更改Tomcat端口
server:
port:
##指定当前工程项目访问地址
context-path: /jdbc

SpringBoot整合JDBC模板的更多相关文章

  1. springboot整合jsp模板

    springboot整合jsp模板 在使用springboot框架里使用jsp的时候,页面模板使用jsp在pom.xnl中需要引入相关的依赖,否则在controller中无法返回到指定页面 〇.搭建s ...

  2. Springboot整合thymeleaf模板

    Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...

  3. springboot整合JDBC出现Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'.

    今天使用springboot整合JDBC的使用,开始使用的是 com.mysql.jdbc.Driver驱动 结果运行出现此异常 那我们根据提示要求来修改即可 把驱动改成最新的com.mysql.cj ...

  4. 3、SpringBoot整合之SpringBoot整合JDBC

    SpringBoot整合JDBC 一.创建SpringBoot项目 选择Spring Web.JDBC API.MySQL Driver 二.在pom配置文件中修改JDBC版本,导入lombok &l ...

  5. 【Springboot】Springboot整合Thymeleaf模板引擎

    Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...

  6. SpringBoot 整合jdbc和mybatis

    摘要 该文章主要为记录如何在SpringBoot项目中整合JDBC和MyBatis,在整合中我会使用简单的用法和测试用例,毕竟该文章目的是为了整合,而不是教大家如何去使用.希望大家多多包涵. 通用配置 ...

  7. springboot整合thymleaf模板引擎

    thymeleaf作为springboot官方推荐使用的模板引擎,简单易上手,功能强大,thymeleaf的功能和jsp有许多相似之处,两者都属于服务器端渲染技术,但thymeleaf比jsp的功能更 ...

  8. 「快学springboot」SpringBoot整合freeMark模板引擎

    前言 虽然现在流行前后端分离开发和部署,但是有时候还是需要用到服务端渲染页面的.比如:需要考虑到SEO优化等问题的时候,FreeMark其实还是很有作用的.本人的博客本来是用React开发的,但是后来 ...

  9. SpringBoot整合jdbc及整合Druid数据源

    一.整合jdbc 1.创建一个springInitializr项目 勾选 web----springweb.SQL----JDBC API,MYSQL Diver 2.连接数据库 3.创建yml 4. ...

随机推荐

  1. c++11多线程记录2:线程管理

    线程没有调用join和detach thread对象必须调用join或者detach,否则程序会终止 例如: void func() { std::cout << "hello, ...

  2. Go基础编程实践(九)—— 网络编程

    下载网页 package main import ( "io/ioutil" "net/http" "fmt" ) func main() ...

  3. mysql 导入sql大文件

    引自:https://dba.stackexchange.com/questions/83125/mysql-any-way-to-import-a-huge-32-gb-sql-dump-faste ...

  4. arc079

    D. Decrease (Contestant ver.) 大意: 每次操作选一个最大数$-n$,其余数全$+1$. 要求构造一个序列$a$, 使得恰好$k$次操作后最大值不超过$n-1$. 只要让$ ...

  5. SpringCloud整合sleuth,使用zipkin时不显示服务

    转载于:https://www.cnblogs.com/Dandwj/p/11179141.html 原文地址:https://blog.csdn.net/weixin_30416497/articl ...

  6. 转:Windows下交换CapsLock和左ctrl

    Windows下交换CapsLock和左ctrlHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout中添加Scanco ...

  7. C# 多线程与高并发处理并且具备暂停、继续、停止功能

    --近期有一个需要运用多线程的项目,会有并发概率,所以写了一份代码,可能有写地方还不完善,后续有需求在改 1 /// <summary> /// 并发对象 /// </summary ...

  8. mysql 5.7 非正常安装,无法启动 服务没有报告任何错误

    以前,完整安装mysql5.7程序时,由于程序太大,可以将安装缓存目录中的安装文件(较小)复制出来后,留以后使用. mysql--win32.msi 2 mysql-5.7.17-winx64.msi ...

  9. python写文件无法换行的问题

    python写文件无法换行的问题,用'\n'  不行,直接打印的出来了. 网上查了查,都说是用  ‘\r\n’ ,但是这样打出来,不仅换行了,还加了一个空行. windows平台最后结果是    直接 ...

  10. 【开发笔记】- MySQL EXPLAIN用法和结果的含义

    转自:http://blog.chinaunix.net/uid-540802-id-3419311.html explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择 ...