springboot(四、springboot+mybatis)
来源:互联网 发布:电子滚动屏幕软件 编辑:程序博客网 时间:2024/05/17 01:32
1、pom.xml中的jar包
这里面重要的是mybatis-spring-boot-starter这个包,目前进行的是简单的数据库访问 不需要导入那么多不必要的jar包
2、application.properties文件里面写访问数据库url还有驱动等等信息,springboot 自带DataSourceAutoConfiguration会自动读取这个文件
3、testMapper.xml(放在resource下)
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" ><mapper namespace="com.example.dao.TestDao" > <select id="obbm" resultType="com.example.entity.TestEntity">select id,biid from obbm </select></mapper>
4、dao层(这里面注解不要忘记)
@Mapperpublic interface TestDao { List<TestEntity> obbm();}
5、service层
public interface TestService {public List<TestEntity> testService();}
6、serviceImpl层
@Servicepublic class TestServiceimpl implements TestService{@Autowiredprivate TestDao td;@Overridepublic List<TestEntity> testService() {System.err.println("service......");return td.obbm();}}
7、controller层
@RestControllerpublic class Hello {@Autowiredprivate TestService ts;@RequestMapping("test")public List<TestEntity> datasource1(){ System.err.println("进入controller");return ts.testService();}}
8、入口(这里面@MapperScan需要写在入口扫描,写在controller是不行的)
@SpringBootApplication@MapperScan("com.example.dao.TestDao")public class DatasourcesApplication {public static void main(String[] args) {SpringApplication.run(DatasourcesApplication.class, args);}}
9、总体的结构
阅读全文
0 0
- springboot(四、springboot+mybatis)
- springBoot(四)整合之MyBatis整合
- springboot笔记(2)springboot-Mybatis使用
- SpringBoot(五):SpringBoot整合MyBatis
- SpringBoot(四):SpringBoot整合JdbcTemplate
- SpringBoot学习(四)SpringBoot和WebSocket
- springboot搭建web(整合mybatis)(四)
- 首页数据分页【springboot mybatis个人博客系统(四)】
- springBoot--mybatis
- springboot + mybatis
- mybatis+springboot
- springboot + mybatis
- springboot mybatis
- springboot+mybatis
- Springboot+Mybatis
- springboot-mybatis
- SpringBoot(四)
- SpringBoot + Mybatis + RESTful(Jersey)
- linux 解压目录下所有的zip文件 find 、xargs
- MVP基类,Retrofit,OkHttp拦截器,RxJava封装
- 关于eclipse中xml文件的注释快捷键
- STM32 HAL 库, 配置串口DMA接收及空闲中断
- CentOS7 安装 MongoDB3.6
- springboot(四、springboot+mybatis)
- elk的安装使用(二)
- Java切割wav音频文件
- Java并发编程札记-(三)JUC原子类-04原子方式更新引用
- pandas基础:Series、和NumPy里的random.x()
- Josn在资源加载中的使用
- vs2013+NetCDF三维数据的读取方法
- 使用navicat for mysql 写一个简单的定时任务。
- intellij idea 显示Arraylist 扩容过程 解决not showing null elements