springboot整合tkmybatis
tkmybatis是什么?
tkmybatis是为了简化mybatis单表的增删改查而诞生的,极其方便的使用MyBatis单表的增删改查,在使用mybatis单表增删改查时,可以直接调用tkmybatis中提供的方法直接调用而不用写xml配置文件。支持单表操作,不支持通用的多表联合查询。
Springboot整合tkmybatis
pom.xml:
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-devtools
runtime
true
org.springframework.boot
spring-boot-starter-test
test
tk.mybatis
mapper
4.1.5
tk.mybatis
mapper-spring-boot-starter
2.1.5
mysql
mysql-connector-java
runtime
org.projectlombok
lombok
true
UserController:
@RestController
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/findById/{id}")
public User findById(@PathVariable int id) {
User user = userService.findById(id);
return user;
}
@RequestMapping("/findAll")
public List findAll() {
List userList = userService.findAll();
return userList;
}
@RequestMapping("/insert")
public void insert() {
User user = new User();
user.setName("张三");
user.setSex("男");
user.setAge(18);
user.setAddress("江西省");
user.setPhone("456789645");
userService.insert(user);
}
@RequestMapping("/delete")
public void delete() {
User user = new User();
user.setId(5);
userService.delete(user);
}
@RequestMapping("/update")
public void update() {
User user = new User();
user.setId(5);
user.setName("李四");
userService.update(user);
}
}
UserService:
public interface UserService {
public User findById(int id);
public List findAll();
public void insert(User user);
public void update(User user);
public void delete(User user);
}
UserServiceImpl:
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public User findById(int id) {
return userMapper.selectByPrimaryKey(id);
}
@Override
public List findAll() {
return userMapper.selectAll();
}
@Override
public void insert(User user) {
userMapper.insertSelective(user);
}
@Override
public void update(User user) {
userMapper.updateByPrimaryKey(user);
}无锡人流医院 http://xmobile.wxbhnk120.com/
@Override
public void delete(User user) {
userMapper.deleteByPrimaryKey(user);
}
}
UserMapper:
public interface UserMapper extends Mapper {
}
application.properties:
#tomcat port
server.port=8080
#datasource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://188.131.247.26:3306/
spring.datasource.username=root
spring.datasource.password=root
#logging
logging.level.com.wyj.mapper:debug
User:
@Data
@Entity
public class User implements Serializable {
@Id
@KeySql(useGeneratedKeys = true)
private Integer id;
private String name;
private String sex;
private Integer age;
private String address;
private String phone;
}
SpringbootTkmybatisApplication:
@SpringBootApplication
@MapperScan("com.wyj.mapper")//tkmybatis的注解
public class SpringbootTkmybatisApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootTkmybatisApplication.class, args);
}
}
springboot整合tkmybatis的更多相关文章
- spring-boot整合mybatis(1)
sprig-boot是一个微服务架构,加快了spring工程快速开发,以及简便了配置.接下来开始spring-boot与mybatis的整合. 1.创建一个maven工程命名为spring-boot- ...
- SpringBoot整合Mybatis之项目结构、数据源
已经有好些日子没有总结了,不是变懒了,而是我一直在奋力学习springboot的路上,现在也算是完成了第一阶段的学习,今天给各位总结总结. 之前在网上找过不少关于springboot的教程,都是一些比 ...
- springboot整合mq接收消息队列
继上篇springboot整合mq发送消息队列 本篇主要在上篇基础上进行activiemq消息队列的接收springboot整合mq发送消息队列 第一步:新建marven项目,配置pom文件 < ...
- springboot整合mybaits注解开发
springboot整合mybaits注解开发时,返回json或者map对象时,如果一个字段的value为空,需要更改springboot的配置文件 mybatis: configuration: c ...
- SpringBoot整合Redis、ApachSolr和SpringSession
SpringBoot整合Redis.ApachSolr和SpringSession 一.简介 SpringBoot自从问世以来,以其方便的配置受到了广大开发者的青睐.它提供了各种starter简化很多 ...
- SpringBoot整合ElasticSearch实现多版本的兼容
前言 在上一篇学习SpringBoot中,整合了Mybatis.Druid和PageHelper并实现了多数据源的操作.本篇主要是介绍和使用目前最火的搜索引擎ElastiSearch,并和Spring ...
- SpringBoot整合Kafka和Storm
前言 本篇文章主要介绍的是SpringBoot整合kafka和storm以及在这过程遇到的一些问题和解决方案. kafka和storm的相关知识 如果你对kafka和storm熟悉的话,这一段可以直接 ...
- SpringBoot整合SpringCloud搭建分布式应用
什么是SpringCloud? SpringCloud是一个分布式的整体解决方案.SpringCloud为开发者提供了在分布式系统中快速构建的工具,使用SpringCloud可以快速的启动服务或构建应 ...
- SpringBoot整合RabbitMQ-整合演示
本系列是学习SpringBoot整合RabbitMQ的练手,包含服务安装,RabbitMQ整合SpringBoot2.x,消息可靠性投递实现等三篇博客. 学习路径:https://www.imooc. ...
随机推荐
- 转:sql 经典50题--可能是你见过的最全解析
题记:从知乎上看到的一篇文章,刚好最近工作中发现遇到的题目与这个几乎一样,可能就是从这里来的吧.^_^ 里面的答案没有细看,SQL求解重在思路,很多时候同一种结果可能有多种写法,比如题中的各科成绩取前 ...
- uniapp - 键盘弹起背景图片不会被挤压
[释义] uni.getSystemInfoSync()获取屏幕可用高度windowScreen做为背景图高度即可(非虚拟DOM也可以使用本思路). [源码] <template> < ...
- Unity3D Substance designer Sub 欧洲小镇场景制作视频教程 中文字幕
大小6.53G,中文字幕 扫码时备注或说明中留下邮箱 付款后如未回复请至https://shop135452397.taobao.com/ 联系店主
- 025_Excel知识汇总
一.Excel相对引用和绝对应用的区别 加上了绝对地址符“$”的列标和行号为绝对地址,在公式向旁边复制时不会发生变化,没有加上绝对地址符号的列标和行号为相对地址,在公式向旁边复制时会跟着发生变化. 具 ...
- 《精通CSS第3版》(5)漂亮的盒子
- 《你必须知道的javascript(上)》- 1.作用域和闭包
1 作用域是什么 1.1 编译原理 分词/词法分析(Tokenizing/Lexing) 将由字符组成的字符串分解成(对编程语言来说)有意义的代码块,这些代码块被称为词法单元(token). 解析/语 ...
- elementui---for循环需要添加KEY
在用VUE和elementui开发项目的时候,在开启 es-lient 的时候,如果for循环没有添加 key ,会报语法上的错误. genderSelect:[ {value:0,label:'女' ...
- (转)nginx 安全配置文档
原文:https://www.cnblogs.com/heaven-xi/p/9961357.html#top 1.配置文档中有多处明确写出了nginx的配置文件路径,该路径是测试环境中的路径,线上系 ...
- aligin-items与aligin-content的区别
align-items 属性使用于所有的flex容器,它是用来设置每个flex元素在侧轴上的默认对齐方式 aligin-items 与align-content有相同的功能,不过不同点是它是用来让每一 ...
- [LeetCode] 653. Two Sum IV - Input is a BST 两数之和之四 - 输入是二叉搜索树
Given a Binary Search Tree and a target number, return true if there exist two elements in the BST s ...