嘻哈飞车族|SpringBoot:数据库访问之Mybatis
点击关注 , 后期更多精彩内容呈上!
在SpringBoot中使用mybatis非常简单 , 我们只需要引入依赖即可 。
1 创建SpringBoot项目并引入依赖
【嘻哈飞车族|SpringBoot:数据库访问之Mybatis】2 创建数据库表及对应的实体类
# 创建表CREATE TABLE `t_demo` (`id` INT(11) NOT NULL AUTO_INCREMENT,`name` VARCHAR(50) NOT NULL,`telphone` VARCHAR(15) NOT NULL,PRIMARY KEY (`id`)) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8public class DemoEntity {private Integer id;private String name;private String telphone;@Overridepublic String toString() {return "DemoEntity[id="+this.id+", name="+this.name+", telphone="+this.telphone+"]";}//省略 getset 方法}3 定义mapper接口及创建对应的xml文件
package com.xw.base.manager.mapper;import com.xw.base.manager.entity.DemoEntity;public interface DemoMapper {DemoEntity selectById(Integer id);int save(DemoEntity entity);void updateDemo(DemoEntity entity);int deleteById(Integer id);}4 定义服务接口及对应的实现
public interface DemoService {DemoEntity selectById(Integer id);int save(DemoEntity entity);void updateDemoEntity(DemoEntity entity);int deleteById(Integer id);}@Servicepublic class DemoServiceImpl implements DemoService {@Autowiredprivate DemoMapper demoMapper;@Overridepublic DemoEntity selectById(Integer id) {return demoMapper.selectById(id);}@Overridepublic int save(DemoEntity entity) {return demoMapper.save(entity);}@Overridepublic void updateDemoEntity(DemoEntity entity) {demoMapper.updateDemo(entity);}@Overridepublic int deleteById(Integer id) {return demoMapper.deleteById(id);}}
推荐阅读
- 「李小璐」李小璐带甜馨现身嘻哈风乐器房,两年前她在此被质疑表白PG1
- 嘻哈段子|我堂哥当年喜欢邻村一个女孩子,天天去她家晃悠,蹭饭吃,幽默笑话:
- 嘻哈飞车族|还有一周:沃尔玛能否成为TikTok最后的买家?
- 嘻哈段子|青椒炒黄瓜,半斤大米肉丝汤?,幽默笑话:床前明月光
- 几品飞车|都2020年了,苹果4G iPhone仍很畅销,说明了什么?
- 一味宠爱|Springboot整合K8s读取ConfigMap刷新配置
- 嘻哈飞车族|要警惕!美国这次来真的:绕开5G研发6G,真不是噱头
- 嘻哈小甜甜|DNF:希洛克困难三次改动!花瓣材料大幅增加,融合SS概率提升
- 中国新说唱|没有火药味的《中国新说唱》太不嘻哈了,没有beef只有Auto-Tune
- 嘻哈小甜甜|KPL首周赛程曝光:3场比赛不容错过,AG复仇Ts,新e星首战AG!
