zoukankan      html  css  js  c++  java
  • SwitchGame---MybatisPLus

    //实体类
    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();
    }

    }
     


  • 相关阅读:
    【Luogu】P3369 【模板】普通平衡树(树状数组)
    文艺平衡树 lg3391(splay维护区间入门)
    普通平衡树 lg3369
    noip2018游记
    webview与壳交互的几种方式
    iOS、Android 之类的如何调试 Web APP
    box-sizing属性
    Hybridapp /webapp调试工具
    DOS 批处理高级教程精选合编
    瀑布流Masonry学习
  • 原文地址:https://www.cnblogs.com/LQ970811/p/12061221.html
Copyright © 2011-2022 走看看