项目搭建及简单增删改查

1:删除html里面的node_modules
2:删除idel里面的 .idel和.mvl
3:导入数据库
4:导入后端源码
5:在HTML前端里面下架包npm install
6:把前端运行起来npm run dev
7:到后端下载MyBatis Plus » 3.5.0的架包
https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter/3.5.2


    com.baomidou
    mybatis-plus-boot-starter
    3.5.2


删除架包          
8:配置后端yml文件

server:
  port: 8080
  servlet:
    context-path: /spboot
spring:
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/crmdb?useUnicode=true&characterEncoding=utf8&useSSL=false
    username: root
    password: 123

9:打开左上角第六个把版本改低一点(1.8)10:编写后台model类
新建Crm类

package com.zking.spboot.model;


import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

@Data
@TableName("teacher")
public class Teacher {

@TableId
private Integer tid;
@TableField("tname")
private String tname;
    @TableField("tjob")
private String tjob;
    @TableField("tsal")
private String tsal;



}


11:建一个Mapper类

package com.zking.spboot.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zking.spboot.model.Crm;
import org.springframework.stereotype.Repository;

@Repository
public interface CrmMapper  extends BaseMapper {
}

12.新建一个controller类

package com.zking.spboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.zking.spboot.mapper.BookMapper;
import com.zking.spboot.model.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BookController {

    @Autowired
    private BookMapper mapper;
    //查询
    @RequestMapping("/list")
    public Object List(String key){
        return mapper.selectList(new QueryWrapper().like(!StringUtils.isEmpty(key),"bookname","%"+key+"%"));
    }
    //增加
    @RequestMapping("/insert")
    public Object insert(Book book){
        return mapper.insert(book);
    }
    //修改
    @RequestMapping("/update")
    public Object update(Book book){
        return mapper.updateById(book);
    }
    //删除
    @RequestMapping("/delete")
    public Object delete(Integer id){
        return mapper.deleteById(id);
    }

}

13:启动SpbootApplication类看一下效果
http://localhost:8080/spboot/list
14:编写前端源码







你可能感兴趣的:(mybatis,java,开发语言)