一、添加依赖:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>

二、注入JdbcTemplate进行数据库操作(或通过MyBatis)

package cn.edu.tju.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {
@Autowired
private JdbcTemplate jdbcTemplate;


@RequestMapping("/set")
public String set(){
jdbcTemplate.execute("create table user_table(x int,y int)");
jdbcTemplate.execute("insert into user_table values(6,88)");
return "set successfully";
}



@RequestMapping("/get")
public String get(){
Integer integer = jdbcTemplate.queryForObject("select y from user_table where x=? limit 1", new Object[]{6}, Integer.class);
return String.valueOf(integer);
}
}