//实体类
package com.example.spring.entity; import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import java.io.Serializable; @Data
@ExcelTarget("SwitchGame")
@TableName("switch")
public class SwitchGame implements Serializable {
@Excel(name = "编号", width = 30, isImportField = "true", orderNum = "0")
private String id;
@Excel(name = "游戏机名称", width = 30, isImportField = "true", orderNum = "0")
private String switchName;
@Excel(name = "游戏机价格", width = 30, isImportField = "true", orderNum = "0")
private String switchPrice;
@Excel(name = "游戏机颜色", width = 30, isImportField = "true", orderNum = "0")
private String switchColor;
@Excel(name = "创建时间", width = 30, isImportField = "true", orderNum = "0")
private String createTime;
@Excel(name = "更新时间", width = 30, isImportField = "true", orderNum = "0")
private String updateTime; public SwitchGame() { } public SwitchGame(String id, String switchName, String switchPrice, String switchColor) {
this.id = id;
this.switchName = switchName;
this.switchPrice = switchPrice;
this.switchColor = switchColor; } public SwitchGame(String id, String switchName, String switchPrice, String switchColor, String createTime, String updateTime) {
this.id = id;
this.switchName = switchName;
this.switchPrice = switchPrice;
this.switchColor = switchColor;
this.createTime = createTime;
this.updateTime = updateTime;
}
}
//Mapper接口层
package com.example.spring.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.spring.entity.SwitchGame;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import utils.Uuid; import java.util.List; @Repository
@EnableTransactionManagement
public interface SwitchGameMapper extends BaseMapper<SwitchGame> {
//列表
List<SwitchGame> selectSwitch(); //添加游戏机
void insertSwitchGame(SwitchGame switchGame); //根据参数添加数据
int insertSwithItems(String name, String price, String color); int delSwitch(String id); //按条件查询
SwitchGame switchById(String id); boolean insetBItems();
}
//Service接口层
package com.example.spring.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.example.spring.entity.SwitchGame; import java.util.List; public interface SwitchGameService extends IService<SwitchGame>
{
List<SwitchGame> selectSwitch();
void insertSwitchGame (SwitchGame switchGame); int insertSwithItems(String name,String price,String color); int delSwitch(String id); //按条件查询
SwitchGame switchById(String id);
boolean insetBItems(); }
//ServiceImpl类(真正的service层)
package com.example.spring.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.spring.entity.SwitchGame;
import com.example.spring.mapper.SwitchGameMapper;
import com.example.spring.service.SwitchGameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.context.support.UiApplicationContextUtils;
import utils.Uuid; import java.util.Arrays;
import java.util.List; @Service
public class SwitchServiceImpl extends ServiceImpl<SwitchGameMapper, SwitchGame> implements SwitchGameService {
@Autowired
private SwitchGameService service;
@Override
public List<SwitchGame> selectSwitch() {
return baseMapper.selectList(null);
} @Override
public void insertSwitchGame(SwitchGame switchGame) {
Uuid uuid = new Uuid();
switchGame.setId(uuid.getUuid());
switchGame.setSwitchName("红桃K");
switchGame.setSwitchPrice("345");
switchGame.setSwitchColor("黑色");
baseMapper.insert(switchGame);
} @Override
public int insertSwithItems(String name, String price, String color) {
Uuid uuid = new Uuid();
SwitchGame switchGame = new SwitchGame(uuid.getUuid(), name, price, color);
return baseMapper.insert(switchGame); } @Override
public int delSwitch(String id) {
return baseMapper.deleteById(id);
} @Override
public SwitchGame switchById(String id) {
return baseMapper.selectById(id);
} @Override
public boolean insetBItems() {
Uuid uuid=new Uuid();
SwitchGame huoqilin=new SwitchGame(uuid.getUuid(),"角斗士","688","橙色"); SwitchGame wuying=new SwitchGame(uuid.getUuid(),"暗杀神","388","橙色"); List<SwitchGame> switchGames= Arrays.asList(huoqilin,wuying);
return service.saveBatch(switchGames);
} }
//Controller层
package com.example.spring.controller;

import com.example.spring.entity.SwitchGame;
import com.example.spring.enums.StateCode;
import com.example.spring.service.impl.SwitchServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.annotation.RequestScope; import java.util.List;
@RestController
@RequestMapping("switch")
public class SwitchGameController {
/***
* 测试
*
* */
@Autowired
private SwitchServiceImpl switchService; @RequestMapping("hello")
public String hello() {
return "Switch Game";
}
@RequestMapping("loaderSwitch")
public String loaderSwitch(){
return "switch"; }
/***
*列表
* */
@RequestMapping("selectSwitchGame")
public List<SwitchGame> selectSwitchGame() {
return switchService.selectSwitch();
}
/***
*根据实体类进行添加
* */
@RequestMapping("insertSwitchGame")
public String insertSwitchGame(SwitchGame switchGame) {
switchService.insertSwitchGame(switchGame);
return StateCode.SUCCESS_INSERT.toString();
}
/***
*根据参数进行添加
* */
@RequestMapping("insertSwithItems")
public StateCode insertSwithItems(String name, String price, String color) {
switchService.insertSwithItems(name, price, color);
return StateCode.SUCCESS_INSERT;
}
/***
*删除
* */
@RequestMapping("delSwitchGame")
public String elSwitchGame(String id)
{
switchService.delSwitch(id);
return StateCode.SUCCESS.getMsg();
}
/***
*按条件查询
* */
@RequestMapping("switchById")
public SwitchGame switchById(String id){ return switchService.switchById(id);
}
/***
*添加多条数据
* */
@RequestMapping("addBatchSwitchGame")
public boolean addBatchSwitchGame(){
return switchService.insetBItems();
} }
 
												

SwitchGame---MybatisPLus的更多相关文章

  1. 优雅高效的MyBatis-Plus工具快速入门使用

    目前正在维护的公司的一个项目是一个ssm架构的java项目,dao层的接口有大量数据库查询的方法,一个条件变化就要对应一个方法,再加上一些通用的curd方法,对应一张表的dao层方法有时候多达近20个 ...

  2. MyBatis-plus 代码自动生成器

    MyBatis-plus  代码自动生成器 1.添加pom文件依赖 <!-- Mybatis-Plus 自动生成实体类--> <dependency> <groupId& ...

  3. MyBatis-plus 代码生成器

    1.添加pom文件依赖 <!-- Mybatis-Plus 自动生成实体类--> <dependency> <groupId>com.baomidou</gr ...

  4. springboot集成mybatisplus

    介绍: Mybatis-Plus(简称MP)是一个 Mybatis 的增强工具,在 Mybatis 的基础上只做增强不做改变,为简化开发.提高效率而生.(摘自mybatis-plus官网)Mybati ...

  5. 基于SpringBoot从零构建博客网站 - 整合lombok和mybatis-plus提高开发效率

    在上一章节中<技术选型和整合开发环境>,确定了开发的技术,但是如果直接这样用的话,可能开发效率会不高,为了提高开发的效率,这里再整合lombok和mybatis-plus两个组件. 1.l ...

  6. 使用Springboot + Gradle快速整合Mybatis-Plus

    使用Springboot + Gradle快速整合Mybatis-Plus 作者:Stanley 罗昊 [转载请注明出处和署名,谢谢!] MyBatis-Plus(简称 MP)是一个 MyBatis ...

  7. Mybatis-Plus入门示例

    1.内容: Mybatis-Plus只是在Mybatis的基础上,实现了功能增强,让开发更加简洁高效. Mybatis-Plus并没有修改Mybatis的任何特性. 2.入门示例: 2.1 需求:使用 ...

  8. MyBatis-plus二级缓存使用

    MyBatis二级缓存使用 注意点: 在最新的3.x版本,实现二级缓存的配置也有了一些改变. 官方建议在service使用缓存,但是你也可以直接在mapper层缓存,这里的二级缓存就是直接在Mappe ...

  9. SpringBoot整合系列--整合MyBatis-plus

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/10125279.html SpringBoot整合MyBatis-plus 步骤 第一步: ...

  10. Mybatis-plus快速入门

    简介 MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发.提高效率而生. 特性 无侵入:只做增强不做改变,引入它不会对现 ...

随机推荐

  1. 04-numpy-笔记-transpose

    借鉴代码https://blog.csdn.net/xiongchengluo1129/article/details/79017142 吐槽一下CSDN的垃圾广告.. 这是转置,所以1维(向量)和2 ...

  2. 在WEB显示实时视频流

    转载自:https://www.jianshu.com/p/7ef5490fbef7 安装摄像头 这里使用的是树莓派的官方摄像头,使用普通的 USB 摄像头也可以,但前提是你能够搞的定它的驱动. 大概 ...

  3. A1038 Recover the Smallest Number (30 分)

    一.技术总结 此问题是贪心类问题,给出可能有前导零的数字串,将他们按照某个顺序拼接,使生成的数最小. 解决方案,就是使用cmp函数,因为两两字符串进行拼接,进行排序从小到大. 拼接过后会有0可能出现在 ...

  4. [LeetCode] 494. Target Sum 目标和

    You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symb ...

  5. 第01组 Beta冲刺(5/5)

    队名:007 组长博客: https://www.cnblogs.com/Linrrui/p/12031875.html 作业博客: https://edu.cnblogs.com/campus/fz ...

  6. css line-height [转]

    原文: http://www.cnblogs.com/dolphinX/p/3236686.html https://www.cnblogs.com/yangjie-space/p/4858132.h ...

  7. asp.net mvc移除X-AspNet-Version、X-AspNetMvc-Version、Server

    asp.net mvc程序部署到IIS,,返回的HTTP头中包含Server, X-Powered-By, 和 X-AspNet-Version.X-AspNet-Version信息. 这些信息有时给 ...

  8. Collection和Collections有什么区别?

        本文链接:https://blog.csdn.net/xiangyuenacha/article/details/84237663 1.java.util.Collection 是一个集合接口 ...

  9. zipfile

    zipfile是一个用于处理zip压缩格式的文件的模块, 主要会用到它的ZipFile类 import zipfile zipfile.is_zipfile('myzip.zip')) # 判断一个文 ...

  10. c++小学期大作业攻略(一)环境配置

    UPDATE at 2019/07/20 20:21 更新了Qt连接mysql的方法,但是是自己仿照连VS的方法摸索出来的,简单测试了一下能work但是不保证后期不会出问题.如果你在尝试过程中出现了任 ...