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);

  }

  }

最新文章

  1. Bash 4.4 中新增的 ${parameter@operator} 语法
  2. 用JS获取地址栏参数的方法
  3. 数据格式json讲解
  4. POI2012
  5. Java 基础知识 练习
  6. jsp连接sqlServer数据库教程
  7. COJ 拯救瑞恩
  8. Magento架构分析,Magento MVC 设计分析
  9. JDK1.7新特性
  10. 在一台电脑访问另一台电脑的mysql数据库,并增加和剥夺权限
  11. MySQL 数据库增量数据恢复案例
  12. JS弄ASP.NET(C#)在页GridView信息选择行
  13. Linux 基本命令-----常用操作分类
  14. WinForm响应式布局设计实践
  15. Mybatis中常用的SQL
  16. Node.js Domain 模块
  17. 算法与数据结构(六) 迪杰斯特拉算法的最短路径(Swift版)
  18. EsayUi中常用的属性和方法总结
  19. leetcode 78,236,300
  20. No mapping found for HTTP request with URI [/crmcrmcrm/css/bootstrap.min.css] in DispatcherServlet with name 'springMvc'

热门文章

  1. koa2 get post api restful前端联调
  2. linux学习(3):linux常用命令大全
  3. Gan-based zero-shot learning 论文整理
  4. python路径相关技巧
  5. 二进制和ASCII文件的区别
  6. js和jquery通过this获取html标签中的属性值[转藏]
  7. Consul服务告警之Watch机制
  8. Postman系列三:Postman中post接口实战(上传文件、json请求)
  9. 【面试】IP数据报格式分析
  10. 【转帖】MIPS构架:曾经是英特尔的“眼中钉”