使用springboot,mybatis-plus和vue的简单增删改查

使用springboot和vue的简单增删改查

目录结构

在这里插入图片描述

controller层
package com.zt.springboot.controller;

import java.util.Arrays;
import java.util.Map;

import com.zt.springboot.utils.PageUtils;
import com.zt.springboot.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zt.springboot.entity.StudentEntity;
import com.zt.springboot.service.StudentService;

/**
 * 
 *
 * @author zhangtao
 * @email [email protected]
 * @date 2022-09-29 22:27:19
 */
@CrossOrigin("*")
@RestController
@RequestMapping("/student")
public class StudentController {
   
    @Autowired
    private StudentService studentService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
   
        PageUtils page = studentService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
   
		StudentEntity student = studentService.getById(id);

        return R.ok().put("student", student);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody StudentEntity student){
   
		studentService.save(student);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody StudentEntity student){
   
		studentService.updateById(student);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
   
		studentService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }
}
dao层
package com.zt.springboot.dao;

import com.zt.springboot.entity.StudentEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;

/**
 * 
 * 
 * @author zhangtao
 * @email [email protected]
 * @date 2022-09-29 22:27:19
 */
@Mapper
public interface StudentDao extends BaseMapper<StudentEntity> {
   
	
}
service层
package com.zt.springboot.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.zt.springboot.entity.StudentEntity;
import com.zt.springboot.utils.PageUtils;

import java.util.Map;

/**
 * 
 *
 * @author zhangtao
 * @email [email protected]
 * @date 2022-09-29 22:27:19
 */
public interface StudentService extends IService<StudentEntity> {
   

    PageUtils queryPage(Map<String, 
  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
课程简介:历经半个多月的时间,Debug亲自撸的 “企业员工角色权限管理平台” 终于完成了。正如字面意思,本课程讲解的是一个真正意义上的、企业级的项目实战,主要介绍了企业级应用系统中后端应用权限的管理,其中主要涵盖了六大核心业务模块、十几张数据库表。 其中的核心业务模块主要包括用户模块、部门模块、岗位模块、角色模块、菜单模块和系统日志模块;与此同时,Debug还亲自撸了额外的附属模块,包括字典管理模块、商品分类模块以及考勤管理模块等等,主要是为了更好地巩固相应的技术栈以及企业应用系统业务模块的开发流程! 核心技术栈列表: 值得介绍的是,本课程在技术栈层面涵盖了前端和后端的大部分常用技术,包括Spring BootSpring MVC、MybatisMybatis-Plus、Shiro(身份认证与资源授权跟会话等等)、Spring AOP、防止XSS攻击、防止SQL注入攻击、过滤器Filter、验证码Kaptcha、热部署插件Devtools、POI、Vue、LayUI、ElementUI、JQuery、HTML、Bootstrap、Freemarker、一键打包部署运行工具Wagon等等,如下图所示: 课程内容与收益: 总的来说,本课程是一门具有很强实践性质的“项目实战”课程,即“企业应用员工角色权限管理平台”,主要介绍了当前企业级应用系统中员工、部门、岗位、角色、权限、菜单以及其他实体模块的管理;其中,还重点讲解了如何基于Shiro的资源授权实现员工-角色-操作权限、员工-角色-数据权限的管理;在课程的最后,还介绍了如何实现一键打包上传部署运行项目等等。如下图所示为本权限管理平台的数据库设计图: 以下为项目整体的运行效果截图: 值得一提的是,在本课程中,Debug也向各位小伙伴介绍了如何在企业级应用系统业务模块的开发中,前端到后端再到数据库,最后再到服务器的上线部署运行等流程,如下图所示:
首先,需要在后端环境中搭建好 Spring BootMyBatis Plus 的开发环境,可以使用 Maven 或 Gradle 等构建工具来引入所需的依赖。 接下来,需要创建一个数据表对应的 Java 实体类,并使用 MyBatis Plus 提供的注解来标识表名、主键、字段等信息。例如: ``` @Data @TableName("user") public class User { @TableId(type = IdType.AUTO) private Long id; private String name; private Integer age; } ``` 然后,创建一个 Mapper 接口,继承自 MyBatis Plus 提供的 BaseMapper 接口,用于定义增删改查等基本操作。例如: ``` public interface UserMapper extends BaseMapper<User> { } ``` 在 Spring Boot 的配置文件中,配置数据库连接信息和 MyBatis Plus 相关配置,例如: ``` spring.datasource.url=jdbc:mysql://localhost:3306/test spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.jdbc.Driver mybatis-plus.configuration.map-underscore-to-camel-case=true ``` 最后,在 Spring Boot 中创建一个 Controller 类,定义对应的请求处理方法,例如: ``` @RestController @RequestMapping("/user") public class UserController { @Autowired private UserMapper userMapper; @GetMapping("/{id}") public User getUserById(@PathVariable("id") Long id) { return userMapper.selectById(id); } @PostMapping("") public void createUser(@RequestBody User user) { userMapper.insert(user); } @PutMapping("/{id}") public void updateUser(@PathVariable("id") Long id, @RequestBody User user) { user.setId(id); userMapper.updateById(user); } @DeleteMapping("/{id}") public void deleteUser(@PathVariable("id") Long id) { userMapper.deleteById(id); } } ``` 这样,就完成了 VueSpring Boot 整合 MyBatis Plus 做增删改查的基本流程。在前端中,可以使用 Axios 等 HTTP 请求库来调用后端的接口。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值