2021-06-29项目实训小程序选座后端第一周(1)

前言

项目实训开始两天,这两天老师给我们讲了大概要求,我作为后端开发组,开始准备一些用到的相关工具和相关知识的学习。

框架工具确定

确定使用Sring boot、mybatis、MySQL
项目使用gitee共同管理
后端使用IDEA开发

下载相关工具以及配置环境

我们后端小组都使用idea写过课设,所以比较熟悉。
MySQL也有相关经验,下载可视化管理工具Navicat Premium方便相关操作。
下载配置git,并尝试用idea将项目上传到gitee上。

遇到的问题

github访问

本来个人打算使用github,搭梯子进行访问(clash for windows),
后团队改用gitee,用法基本一致。

上传项目

在上传时遇到:错误信息
发现是因为没有配置好git,需要通过git bash运行下面两行代码:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

SpringBoot大体结构

在这里插入图片描述
根据学的东西,自己尝试写了一个比较简单的demo
主要有UserController.java,UserService.java,UserServiceImp.java,UserMapper.java和User实体类,方便理解。
Controller.java:

package com.example.springbootstudy.controller;

import com.example.springbootstudy.entity.User;
import com.example.springbootstudy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("api/user")
public class UserController {
    @Autowired
    UserService userService;
    //请求所有
    @GetMapping("queryAllIo")
    public ArrayList<User> queryAllIo(){
        return userService.queryAllIo();
    }
    //根据条件查询
    @GetMapping("/queryUserById")
    public List<User> queryDeviceById(@RequestParam("id")int id){
        if (id != 0){
            return userService.queryUserById(id);
        }else {
            return userService.queryAllIo();
        }
    }
    //插入
    @PostMapping("addUser")
    int addDevice(@RequestParam("userid")int userid,
                  @RequestParam("name")String name){
        return userService.insertUser(userid,name);
    }

}

UserService.java

package com.example.springbootstudy.service;

import com.example.springbootstudy.entity.User;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

public interface UserService {
    //查询记录
    ArrayList<User> queryAllIo();

    //根据条件查询
    List<User> queryUserById(int id);

    //插入user
    int insertUser(int userid,String name);
}

UserServiceImp.java

package com.example.springbootstudy.serviceImp;

import com.example.springbootstudy.entity.User;
import com.example.springbootstudy.mapper.UserMapper;
import com.example.springbootstudy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImp implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public ArrayList<User> queryAllIo() {
        return userMapper.queryAllIo();
    }

    @Override
    public List<User> queryUserById(int id){
        return userMapper.queryUserById(id);
    }

    @Override
    public int insertUser(int userid, String name) {
        return userMapper.insertUser(userid,name);
    }

}

UserMapper.java

package com.example.springbootstudy.mapper;

import com.example.springbootstudy.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;
import java.util.List;

@Mapper
public interface UserMapper {
    //查询所有记录
    @Select("select * from users")
    ArrayList<User> queryAllIo();

    //根据条件查值
    @Select("select * from users where userid = #{id}")
    List<User> queryUserById(@Param("id")int id);

    //插入
    @Insert("insert into users (userid,name) values (#{userid},#{name})")
    int insertUser(@Param("userid")int userid,
                     @Param("name")String name);
}

总结

前两天,大致了解了基本使用技术,简单配置完成,接下来准备根据需求进行分析和接口文档的设计。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值