Springboot 项目 连接人大金仓数据库,进行功能查询demo示例
前言
由于公司准备进行信创改造,所以我这里就先验证项目连接人大金仓数据库进行验证, 人大金仓的下载安装以及数据迁移上一篇已介绍
一、数据库连接
spring:datasource:driver-class-name: com.kingbase8.Driverurl: jdbc:kingbase8://localhost:54321/test?currentSchema=itomusername: rootpassword: root
二、功能示例
1.controller
代码如下(示例):
import com.mybatisflex.flex.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api")
public class TestController {@Autowiredprivate TestService testService;@GetMapping("getInfo")public String getInfo() {return testService.getInfo();}
}
2.service层
代码如下(示例):
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.flex.domain.Duty;
import org.apache.ibatis.annotations.Mapper;@Mapper
public interface TestMapper extends BaseMapper<Duty> {
}
3.dao层
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.flex.domain.Duty;
import org.apache.ibatis.annotations.Mapper;@Mapper
public interface TestMapper extends BaseMapper<Duty> {
}
5.实体类
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import lombok.Data;@Data
@Table(value = "duty", schema = "itom")
public class Duty {@Id(keyType = KeyType.Auto)private Long id;@Column(value = "location")private String location;
}