springboot整合mybatis-plus

Posted Gendan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot整合mybatis-plus相关的知识,希望对你有一定的参考价值。

package com.guigu.liujie.controller;

import com.guigu.liujie.pojo.User;
import com.guigu.liujie.service.UserService;
import com.guigu.liujie.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * @ClassName UserController
 * @Description TODO
 * @Author liujie
 * @Date 2021/6/15 16:19
 * @Version 1.0
 **/
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    public UserService userService;
    /**
     * 用户新增
     * @param user
     * @return
     */
    @PostMapping()
    public Object userAdd(@RequestBody User user){
        boolean isAdd = userService.userAdd(user);
        if(!isAdd){
            return new Result(isAdd,"新增失败");
        }
        return new Result([PerfectMoney下载](https://www.gendan5.com/wallet/PerfectMoney.html)isAdd,"新增成功");
    }
    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping(value = "{id}")
    public Object userDel(@PathVariable Integer id){
        boolean flag = userService.userDel(id);
        if(!flag){
            return new Result(flag,"删除失败");
        }
        return new Result(flag,"删除成功");
    }
    /**
     * 根据当前用户id进行修改
     * @param user
     * @return
     */
    @PutMapping()
    public Object userUpd(@RequestBody User user){
        boolean flag = userService.userUpd(user);
        if(!flag){
            return new Result(flag,"修改失败");
        }
        return new Result(flag,"修改成功");
    }
    /**
     * 查询所有用户信息
     * @return
     */
    @GetMapping()
    public Object findAll(){
        List<User> userList = userService.findAll();
        return new Result("查询所有成功",userList);
    }
    /**
     * 根据id查看详情
     * @param id
     * @return
     */
    @GetMapping(value = "{id}")
    public Object findById(@PathVariable Integer id){
        User user = userService.findById(id);
        if(user!=null){
            return new Result("查看详情成功",user);
        }
        return new Result("查看详情失败",user);
    }
}

以上是关于springboot整合mybatis-plus的主要内容,如果未能解决你的问题,请参考以下文章

springboot整合mybatis-plus

springboot整合mybatis-plus+durid数据库连接池

mybatis-plus整合springboot入门

mybatis-plus整合springboot入门

Springboot整合Mybatis-Plus

springboot 整合Mybatis-Plus分页自动填充功能