12---实现注册、异常处理,统一封装结果集

news2024/9/25 23:14:17

1、写统一返回结果包装类

  1. 在实际开发中,为了降低开发人员之间的沟通成本,一般返回结果会定义成一个统一格式,具体的格式根据实际开发业务不同有所区别,但至少包括三要素:
  • code状态码:由后端统一定义各种返回结果的状态码
  • message 描述:本次接口调用的结果描述
  • data 数据:本次返回的数据。
  1. 创建common包,创建Result.java

Result.java

package com.xqh.common;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/*
* 接口统一返回包装类
*
* */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {
    private String code;
    private String msg;
    private Object data;

    //没有数据,成功时
    public static Result success(){
        return new Result(Constants.CODE_200,"",null);
    }

    //有数据,成功时
    public static Result success(Object data){
        return new Result(Constants.CODE_200,"",data);
    }

    //失败 ,有状态码
    public static Result error(String code,String msg){
        return new Result(code,msg,null);
    }

    //失败,默认一个
    public static Result error(){
        return new Result(Constants.CODE_500,"系统错误",null);
    }
}

  1. 写一个constants,放这些状态码
package com.xqh.common;

public interface Constants {
    String CODE_200 ="200"; //成功

    String CODE_500 ="500";  //系统错误
    String CODE_401="401";   //权限不足
    String CODE_400="400";  //参数错误
    String CODE_600 ="600";  //其他业务异常
}

  • 这些状态码都可以自定义,根据自己的需要,自定义这些状态码

2、改造接口

  1. 因为写了把结果统一包装了,所以controller里面的接口都要改造成返回Result类

UserController.java

//登录
    @PostMapping("/login")
    public Result login(@RequestBody UserDTO userDTO){
        //先验证都不为空,再去比对数据库
        String username = userDTO.getUsername();
        String password = userDTO.getPassword();
        if (StrUtil.isBlank(username) || StrUtil.isBlank(password)){
            return Result.error(Constants.CODE_400,"参数错误");
        }
        UserDTO dto = userService.login(userDTO);
        return Result.success(dto);
    }

  //插入和修改操作
    @PostMapping
    public Result save(@RequestBody User user){
        return Result.success(userService.saveOrUpdate(user));
    }

    //查询所有数据
    @GetMapping
    public Result findAll(){
        return Result.success(userService.list());
    }

    //删除
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        return Result.success(userService.removeById(id));
    }

    //批量删除
    @PostMapping ("/del/batch")
    public Result deleteBatch(@RequestBody List<Integer>ids){
        return Result.success(userService.removeBatchByIds(ids));
    }

 //根据id查找用户信息
    @GetMapping("{id}")
    public Result findOneById(@PathVariable Integer id){
        return Result.success(userService.getById(id));
    }


//分页查询
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                                @RequestParam Integer pageSize,
                                @RequestParam(defaultValue = "") String username,
                                @RequestParam(defaultValue = "") String email,
                                @RequestParam(defaultValue = "") String address){
      return Result.success(userService.findPage(pageNum,pageSize,username,email,address));

    }


  //导入

    @PostMapping("/import")
    public Result imp(MultipartFile file) throws Exception{
        InputStream inputStream = file.getInputStream();
        ExcelReader reader = ExcelUtil.getReader(inputStream);
        List<User> list = reader.readAll(User.class);   //要对应上自己数据库的字段名
        System.out.println(list);
        //导入到后端来,进行插入到数据库中
        userService.saveBatch(list);
        return Result.success(true);

    }
  1. 接口改造后,前端也要该,在响应请求接口的地方,用res.data代替res,后面写注册功能再提供完整代码。

3、全局异常处理

  1. 自定义全局异常

创建一个新的包exception

创建GlobalExceptionHandle.java

package com.xqh.exception;
import com.xqh.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    public Result handle(ServiceException se){
        return Result.error(se.getCode(),se.getMessage());
    }
}

ServiceException.java

package com.xqh.exception;

import lombok.Getter;

@Getter
public class ServiceException extends RuntimeException {
    private String code;
    public ServiceException(String code,String msg){
        super(msg);
        this.code=code;
    }

}

  1. 使用全局异常

之前写的登录的业务代码

UserService.java

 //登录
    public UserDTO login(UserDTO userDTO) {
        User one = getUserInfo(userDTO);
        if (one !=null){
           BeanUtil.copyProperties(one,userDTO,true);
           return userDTO;
       }else {
           throw new ServiceException(Constants.CODE_600,"用户名或密码错误");  //抛出异常
       }


    }

4、实现注册

  1. SpringBoot中写注册接口
  • UserController.java
//注册接口
    @PostMapping("/register")
    public Result register(@RequestBody UserDTO userDTO){
        //先验证都不为空,再去添加到数据库
        String username = userDTO.getUsername();
        String password = userDTO.getPassword();
        if (StrUtil.isBlank(username) || StrUtil.isBlank(password)){
            return Result.error(Constants.CODE_400,"参数错误");
        }
        return Result.success(userService.register(userDTO));
    }

  • UserService.java
  public User register(UserDTO userDTO) {
        User one = getUserInfo(userDTO);
        if (one==null){
            one=new User();
            BeanUtil.copyProperties(userDTO,one,true);
            save(one);  //把copy完之后的用户对象存储到数据库
        }else {
            throw new ServiceException(Constants.CODE_600,"用户已存在");
        }
        return one;


    }


//将相同代码操作封装起来使用更方便,减去重复代码编写
    private User getUserInfo(UserDTO userDTO){
        QueryWrapper<User>queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",userDTO.getUsername());
        queryWrapper.eq("password",userDTO.getPassword());
        User one;
        try{
            one =getOne(queryWrapper);//从数据库中查询用户信息
        }catch(Exception e){
            LOG.error(e);
            throw new ServiceException(Constants.CODE_500,"系统错误");
        }
        return one;
    }
  1. Vue前端实现注册
  • 写注册页面Register.vue
<template>
    <div class="wrapper">
        <div style="margin: 100px auto;background-color: #fff;width:350px;height:400px;padding:20px;border-radius:10px">
        
            <div style="margin: 20px 0;text-align:center;font-size:24px"><b>注 册</b></div>
          <el-form :model="user" :rules="rules" ref="userForm">
            <el-form-item prop="username">
                <el-input placeholder="请输入用户名"  size="medium" style="margin: 10px 0" prefix-icon="el-icon-user" v-model="user.username"></el-input>
            </el-form-item>
            <el-form-item prop="password">
                <el-input placeholder="请输入密码" size="medium" style="margin: 10px 0" prefix-icon="el-icon-lock" show-password v-model="user.password"></el-input>
            </el-form-item>
            <el-form-item prop="confirmPassword">
                <el-input placeholder="请确认密码"  size="medium" style="margin: 10px 0" prefix-icon="el-icon-lock" show-password v-model="user.confirmPassword"></el-input>
            </el-form-item>
            <el-form-item prop="nickname">
                <el-input placeholder="请输入昵称" size="medium" style="margin: 10px 0" prefix-icon="el-icon-lock"  v-model="user.nickname"></el-input>
            </el-form-item>
            
            <el-form-item style="margin: 10px 0;text-align: right">
                <el-button type="primary" size="small" autocomplete="off" @click="login">注册</el-button>
                <el-button type="warning" size="small" autocomplete="off" @click="$router.push('/login')">返回登录</el-button>
            </el-form-item>
          </el-form>
        </div>
    </div>
</template>

<script>
export default{
    name: "Login",
    data(){
        return{
            user: {},
            rules: {
                username: [
                    { required: true, message: '请输入用户名', trigger: 'blur' },
                    { min: 3, max:10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    { min: 5, max: 20, message: '长度在 5 到 20 个字符', trigger: 'blur' }
                ],
                confirmPassword: [
                    { required: true, message: '请确认密码', trigger: 'blur' },
                    { min: 5, max: 20, message: '长度在 5 到 20 个字符', trigger: 'blur' }
                ],
                nickname: [
                    { required: true, message: '请输入昵称', trigger: 'blur' },
                    { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
                ]
                }
    }
    },
    methods:{
        login(){
            //前端不通过的时候登录不去请求后端
            this.$refs['userForm'].validate((valid)=>{
                if (valid) {  //表单检验合法
                    if(this.user.password!==this.user.confirmPassword){
                        this.$message.error("两次输入的密码不一致")
                        return false
                    }
                    this.request.post("/user/register",this.user).then(res => {
                if(res.code==='200'){
                    this.$message.success("注册成功!")
                    this.$router.push("/login")
                }else{
                    this.$message.error(res.msg)
                    
                }
            })
          }
            })
           
        }


    }


}
</script>

<style>

    .wrapper{
        height: 100vh;
        background-image: linear-gradient(to bottom right,#FC466B, #3F5EFB);
        overflow: hidden;
    }



</style>

复制登录页面,然后加以修改即可

  • 去index.js中注册
 {
    path: '/register',
    name: 'Register',
    component:()=>import('../views/Register.vue')
  }
  • 在登录页面中实现按注册跳转到注册页面
                <el-button type="warning" size="small" autocomplete="off" @click="$router.push('/register')">注册</el-button>

在这里插入图片描述

  • 注册成功后返回到登录页面

5、完善登录

  1. 登录成功后到主页,显示当前登录用户的昵称
                <el-button type="primary" size="small" autocomplete="off" @click="login">登录</el-button>
//写一个登录的方法
<script>
   login(){
            //前端不通过的时候登录不去请求后端
            this.$refs['userForm'].validate((valid)=>{
                if (valid) {  //表单检验合法
                    this.request.post("/user/login",this.user).then(res => {
                if(res.code==='200'){
                    localStorage.setItem("user",JSON.stringify(res.data)) //存储用户信息到浏览器里面
                    this.$router.push("/")
                    this.$message.success("登录成功!")
                }else{
                    this.$message.error(res.msg)
                    
                }
            })
          }
</script>

  • 将登录后,传过来的UserDto储存在浏览器里,后面需要使用直接调用

Header.vue

        <span>{{user.nickname}}</span><i class="el-icon-arrow-down" style="margin-left:5px"></i>
  


data(){
        return{
            user: localStorage.getItem("user")?JSON.parse(localStorage.getItem("user")):{}

        }
logout(){
            this.$router.push("/login")
            localStorage.removeItem("user")
            this.$message.success("退出成功")
        }//退出后,删除存储在浏览器的数据

  • 效果如图

在这里插入图片描述

登录后自动获取当前用户的昵称并显示

6、编写个人信息功能

  1. 直接注册很多信息不完善,可以在点击个人下面个人信息进行修改

  2. 编写个人信息页

Person.vue

<template>
   <el-card style="width:500px;padding:20px;">
    <el-form label-width="80px" size="small">
          <el-form-item label="用户名" >
            <el-input v-model="form.username" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="昵称" >
            <el-input v-model="form.nickname" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="邮箱" >
            <el-input v-model="form.email" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="电话" >
            <el-input v-model="form.phone" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="地址" >
            <el-input v-model="form.address" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="save">确 定</el-button>
          </el-form-item>
        </el-form>
   </el-card>
</template>

<script>
export default{
    name:"Person",
    data(){
        return{
            form:{},
            user:localStorage.getItem("user")?JSON.parse(localStorage.getItem("user")):{}
        }
    },
    created(){
        this.request.get("/user/username/"+this.user.username).then(res=>{
            if(res.code==='200'){
                this.form=res.data
            }

        })


    },
    methods:{

        save(){
      this.request.post("/user",this.form).then(res=>{
        if(res.data){
          this.$message.success("保存成功!")
        }else{
          this.$message.error("保存失败!")
        }
      })

    }


    }
}

</script>

<style>

</style>
  • 根据登录成功后储存在浏览器中的用户名,来向后端请求当前用户的完整信息

后端通过用户名查询数据的接口:

  //根据用户名查找用户信息
    @GetMapping("/username/{username}")
    public Result findOneByName(@PathVariable String username){
        QueryWrapper<User>queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("username",username);
        return Result.success(userService.getOne(queryWrapper));
    }
  • 找到后储存在浏览器中,并更新form中的数据,更新为res.data,并显示出来,这样个人信息就拿到了当前用户的信息。然后执行的是更新操作。
  • 点击确定即更新成功

在这里插入图片描述

7、完整前端代码

  1. 因为接口改造,导致前端请求接口的代码也要稍作修改。下面是完整代码。
  • Header.vue
<template>
    <div style="font-size: 12px;line-height:60px;display: flex;">
        <div style="flex:1;font-size:18px">
       <span :class="collapseBtnClass" style="cursor:pointer" @click="collapse"></span>
       <el-breadcrumb separator="/" style="display:inline-block;margin-left: 10px;">
        <el-breadcrumb-item :to="'/'">首页</el-breadcrumb-item>
        <el-breadcrumb-item>{{currentPathName}}</el-breadcrumb-item>
       </el-breadcrumb> 
     </div>
     <el-dropdown style="width:70px;cursor:pointer" >
        <span>{{user.nickname}}</span><i class="el-icon-arrow-down" style="margin-left:5px"></i>

       <el-dropdown-menu slot="dropdown" style="width:100px; text-align:center">
         <el-dropdown-item style="font-size:14px;padding:5px 0">
                 <router-link to="/person" style="text-decoration:none">个人信息</router-link>
        </el-dropdown-item>
         <el-dropdown-item style="font-size:14px;padding:5px 0">
            <span style="text-decoration: none" @click="logout"> 退出</span>
           </el-dropdown-item>
       </el-dropdown-menu>
     </el-dropdown>
    </div>
</template>

<script>
export default{
    name:"Header",
    props:{
        collapseBtnClass:String,
        collapse:Function
    },
    computed:{
        currentPathName(){
            return this.$store.state.currentPathName;  //需要监听的数据
        }
    },
    data(){
        return{
            user: localStorage.getItem("user")?JSON.parse(localStorage.getItem("user")):{}

        }
    },
    methods:{
        collapse(){
            this.$emit("asideCollapse")
        },
        logout(){
            this.$router.push("/login")
            localStorage.removeItem("user")
            this.$message.success("退出成功")
        }
    }

}

</script>

<style scoped>

</style>
  • Login.vue
<template>
    <div class="wrapper">
        <div style="margin: 200px auto;background-color: #fff;width:350px;height:300px;padding:20px;border-radius:10px">
        
            <div style="margin: 20px 0;text-align:center;font-size:24px"><b>登 录</b></div>
          <el-form :model="user" :rules="rules" ref="userForm">
            <el-form-item prop="username">
                <el-input  size="medium" style="margin: 10px 0" prefix-icon="el-icon-user" v-model="user.username"></el-input>

            </el-form-item>
            <el-form-item prop="password">
                <el-input  size="medium" style="margin: 10px 0" prefix-icon="el-icon-lock" show-password v-model="user.password"></el-input>

            </el-form-item>
            <el-form-item style="margin: 10px 0;text-align: right">
                <el-button type="primary" size="small" autocomplete="off" @click="login">登录</el-button>
                <el-button type="warning" size="small" autocomplete="off" @click="$router.push('/register')">注册</el-button>
            </el-form-item>
          </el-form>
        </div>
    </div>
</template>

<script>
export default{
    name: "Login",
    data(){
        return{
            user: {},
            rules: {
                username: [
                    { required: true, message: '请输入用户名', trigger: 'blur' },
                    { min: 3, max:10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    { min: 5, max: 20, message: '长度在 5 到 20 个字符', trigger: 'blur' }
                ]
                }
    }
    },
    methods:{
        login(){
            //前端不通过的时候登录不去请求后端
            this.$refs['userForm'].validate((valid)=>{
                if (valid) {  //表单检验合法
                    this.request.post("/user/login",this.user).then(res => {
                if(res.code==='200'){
                    localStorage.setItem("user",JSON.stringify(res.data)) //存储用户信息到浏览器里面
                    this.$router.push("/")
                    this.$message.success("登录成功!")
                }else{
                    this.$message.error(res.msg)
                    
                }
            })
          }
            })
           
        }


    }


}
</script>

<style>

    .wrapper{
        height: 100vh;
        background-image: linear-gradient(to bottom right,#FC466B, #3F5EFB);
        overflow: hidden;
    }



</style>

  • User.vue
<template>
    <div>
     <div style="padding:10px 0">
       <el-input style="width:200px" placeholder="请输入用户名" suffix-icon="el-icon-search" v-model="username"></el-input>
        <el-input style="width:200px" placeholder="请输入邮箱" suffix-icon="el-icon-message" class="ml-5" v-model="email"></el-input>
       <el-input style="width:200px" placeholder="请输入地址" suffix-icon="el-icon-position" class="ml-5" v-model="address"></el-input>
       <el-button class="ml-5" type="primary" @click="load">搜索</el-button>
       <el-button  type="warning" @click="reset">重置</el-button>
      
     </div>

     <div style="margin:10px 0">
       <el-button type="primary" @click="handleAdd">新增<i class="el-icon-circle-plus-outline"></i></el-button>
       <el-popconfirm
                class="ml-5"
                confirm-button-text='确定'
                cancel-button-text='我再想想'
                icon="el-icon-info"
                icon-color="red"
                title="您确定要删除这些内容吗?"
                @confirm="delBatch"
          >
          <el-button type="danger"  slot="reference">批量删除<i class="el-icon-remove-outline"></i></el-button>
          </el-popconfirm>
          <el-upload action="http://localhost:8081/user/import" :show-file-list="false" accept="'xlsx'" :on-success="handleImportSuccess" style="display:inline-block">
       <el-button type="primary" class="ml-5">导入<i class="el-icon-top"></i></el-button>
          </el-upload>
       <el-button type="primary" @click="exp" class="ml-5">导出<i class="el-icon-bottom"></i></el-button>
     </div>






     <el-table :data="tableData" border stripe :header-cell-calss-name="'headerBg'"    @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="id" label="ID" width="80"></el-table-column>
       <el-table-column prop="username" label="用户名" width="140"></el-table-column>
       <el-table-column prop="nickname" label="昵称" width="120"></el-table-column>
       <el-table-column prop="email" label="邮箱" ></el-table-column>
       <el-table-column prop="phone" label="电话" ></el-table-column>
       <el-table-column prop="address" label="地址"></el-table-column>
       <el-table-column label="操作" width="200" align="center">
         <template slot-scope="scope" >
           <el-button type="success" @click="handleUpdate(scope.row)">编辑 <i class="el-icon-edit"></i></el-button>
          <el-popconfirm
                class="ml-5"
                confirm-button-text='确定'
                cancel-button-text='我再想想'
                icon="el-icon-info"
                icon-color="red"
                title="您确定要删除吗?"
                @confirm="handleDelete(scope.row.id)"
          >
          <el-button type="danger" slot="reference">删除<i class="el-icon-remove-outline"></i></el-button>
          </el-popconfirm>
         </template>
       </el-table-column>
     </el-table>
     <div style="padding:10px 0">
       <el-pagination
       @size-change="handleSizeChange"
       @current-change="handleCurrentChange"
         :current-page="pageNum"
         :page-sizes="[2, 4, 6, 10]"
         :page-size="pageSize"
         layout="total, sizes, prev, pager, next, jumper"
         :total="total">
       </el-pagination>
     </div>

      <el-dialog title="用户信息" :visible.sync="dialogFormVisible" width="30%">
        <el-form label-width="80px" size="small">
          <el-form-item label="用户名" >
            <el-input v-model="form.username" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="昵称" >
            <el-input v-model="form.nickname" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="邮箱" >
            <el-input v-model="form.email" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="电话" >
            <el-input v-model="form.phone" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="地址" >
            <el-input v-model="form.address" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="save">确 定</el-button>
        </div>
      </el-dialog>
    </div>
</template>

<script>
export default{
    name:"User",
    data() {
     return {
       tableData:[],
       total: 0 ,
       pageNum:1,
       pageSize:4,
       username:"",
       email:"",
       address:"",
       form:{},
       dialogFormVisible:false,
       multipleSelection:[]
     }
    },
    created(){
        this.load()

    },
    methods:{
        load(){
      this.request.get("/user/page",{
        params:{
        pageNum:this.pageNum,
        pageSize:this.pageSize,
        username:this.username,
        email:this.email,
        address:this.address

      }
        }).then(res=>{
        console.log(res)
        this.tableData=res.data.records
        this.total=res.data.total 
      })
     },
     save(){
      this.request.post("/user",this.form).then(res=>{
        if(res.data){
          this.$message.success("保存成功!")
          this.dialogFormVisible=false
          this.load()
        }else{
          this.$message.error("保存失败!")
        }
      })


     },
     handleAdd(){

      this.dialogFormVisible=true
      this.form={}

     },
     handleUpdate(row){
      this.form={...row}
      this.dialogFormVisible=true
     
     },
     handleDelete(id){
      this.request.delete("/user/" + id).then(res=>{
        if(res.data){
          this.$message.success("删除成功!")
          this.load()
        }else{
          this.$message.error("删除失败!")
        }
      })
     },
     delBatch(){
      let ids=this.multipleSelection.map(v=>v.id)  //把对象数组转化为id数组【1,2,3】
      request.post("/user/del/batch",ids).then(res=>{
        if(res.data){
          this.$message.success("批量删除成功!")
          this.load()
        }else{
          this.$message.error("批量删除失败!")
        }
      })

     },
     handleSelectionChange(val){
      this.multipleSelection=val



     },
     reset(){
      this.username=""
      this.email=""
      this.address=""
      this.load()

     },
    
     handleSizeChange(pageSize){
      this.pageSize=pageSize
      this.load()
     },
     handleCurrentChange(pageNum){
      this.pageNum=pageNum
      this.load()
     },
     exp(){
      window.open("http://localhost:8081/user/export")
     } ,
     handleImportSuccess(){
      this.$message.success("文件导入成功!")
      this.load()
     }

    }
}

</script>

<style>
.headerBg{
    background: #eee!important;
}
</style>
  • 改造完代码,每个功能都测试一下。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/131281.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

3)Django模板

目录 Django模板 Django 模板标签 变量 ​编辑 列表 字典 过滤器 default length filesizeformat date truncatechars safe if/else 标签 for 标签 {% empty %} ifequal/ifnotequal 标签 注释标签 include 标签 csrf_token 配置静态文件 模板继承 父模板…

Elasticsearch搜索引擎(一)——基础使用

Elasticsearch搜索引擎 关键词是中文的建议使用&#xff0c;英文和数字不要&#xff0c;模糊就行 如果普通数据库查询&#xff0c;无法解决如下问题 如果表记录上千万上亿了这个性能问题&#xff0c;另外一个如果有一个本文字段要在里面模糊配置&#xff0c;这个就会出现严重…

【408篇】C语言笔记-第二十章(数据的机器级表示)

文章目录第一节&#xff1a;补码讲解及内存实战演练1. 补码讲解2. 反码第二节&#xff1a;整型不同类型解析-溢出解析1. 整型不同类型解析2. 溢出解析第三节&#xff1a;IEEE754标准解析第四节&#xff1a;浮点型精度丢失第一节&#xff1a;补码讲解及内存实战演练 1. 补码讲解…

使用华为云服务器跟做尚硅谷电商数仓遇到的问题汇总(持续更新中.......)

文章目录使用xsync时提示xsync:command not found执行lg.sh时显示lg.sh:command not found云服务器网页无法访问hadoop使用xsync时提示xsync:command not found 1.使用xsync时提示xsync:command not found 首先查看是否安装rsync:&#xff08;反正我的里面没有。。。&#xff…

实验十、差分放大电路参数对静态和动态的影响

一、题目 利用Multism研究图1所示差分放大电路在下列情况下对电路静态和动态的影响 &#xff08;1&#xff09;两个 RcR_cRc​ 阻值相差 5%&#xff1b; &#xff08;2&#xff09;RwR_wRw​ 不在中点&#xff1b; &#xff08;3&#xff09;两个差分管的电流放大倍数不相等。…

sql行转列

我们以MySQL数据库为例&#xff0c;来说明行转列的实现方式。 首先&#xff0c;假设我们有一张分数表&#xff08;tb_score&#xff09;&#xff0c;表中的数据如下图&#xff1a; 然后&#xff0c;我们再来看一下转换之后需要得到的结果&#xff0c;如下图&#xff1a; 可以看…

SpringBoot(一)【学习笔记】

1.SpringBoot是什么&#xff1f; Spring Boot是为了简化Spring应用的创建、运行、调试、部署等而出现的&#xff0c;使用它可以做到专注于Spring应用的开发&#xff0c;而无需过多关注XML的配置。 2.SpringBoot的特点 为基于Spring的开发提供更快的入门体验 开箱即用&#xf…

Qt QAbstractItemModel类详解

文章目录一.概述二.QAbstractItemModel类1.类型2.信号3.函数一.概述 QAbstractItemModel 类定义了项目模型必须使用的标准接口&#xff0c;以便能够与模型/视图Model/View框架中的其他组件进行互操作。 正确用法是将其子类化以创建新模型。此类用作 QML 中的项目视图元素或 Qt…

自制Alfred/Wox插件推荐

最近上手Alfred的使用&#xff0c;日常工作中存在很多需要高频执行的连续性动作&#xff0c;将这一系列动作封装成Workflow&#xff0c;通过命令触发&#xff0c;对提升效率确有很大帮助。 自己封装了一些简单的Workflow&#xff0c;这里分享出来。有Alfred/Wox框架的支撑&…

JAVA零基础小白学习免费教程day14-SetHashMap

day14_JAVAOOP 课程目标 1. 【理解】Set集合的特点 2. 【理解】Set集合不重复的原理 3. 【掌握】HaseSet集合的基本使用 4. 【理解】LinkedHashSet的特点 5. 【理解】Map集合的特点 6. 【掌握】HashMap的使用 7. 【理解】LinkedHashMap的特点 8. 【掌握】Map集合的案例 9. 【…

doxygen教程之注释风格

作者&#xff1a;朱金灿 来源&#xff1a;clever101的专栏 为什么大多数人学不会人工智能编程&#xff1f;>>> doxygen是一个开源的C接口文档生成工具。要使用doxygen生成接口文档&#xff0c;就必须遵循它的注释规范&#xff0c;下面对它的注释规范进行简单介绍。 …

C语言基础--初识指针

文章目录一、初识指针二、指针和指针类型指针类型的意义1&#xff09;指针的解引用①问题抛出②探讨③总结2&#xff09;指针整数3&#xff09;总结4)举例三、野指针&#xff08;1&#xff09;概念1) 指针未初始化2)指针越界访问3&#xff09;指针指向的空间释放&#xff08;2&…

python类中常见内置方法

目录 一.几种常用的类内置方法 魔术方法 _ _str_ _字符串方法 _ _lt_ _小于符号比较方法 _ _le_ _小于等于比较符号方法 _ _eq_ _等于比较符号 一.几种常用的类内置方法 魔术方法 上文提到的_ _init_ _构造方法&#xff0c;是Python类内置的方法之一。 这些内置的类方法…

人工智能-聚类算法

1、聚类算法简介 典型的无监督算法&#xff0c;主要用于将相似的样本自动归到一个类别中。 根据样本之间的相似性&#xff0c;将样本划分到不同的类别中&#xff0c;对于不同的相似度计算方法&#xff0c;会得到不同的聚类结果。常用的相似度计算方法是欧式距离法 聚类算法与…

2022年总结 2023展望

前言 今天是2022年最后一天&#xff0c;姑且简单总结这一年。这一年从头到尾发生了很多翻天覆地的事件。回看去年2021年的年度总结还是有些遗憾&#xff0c;完成度4/7。 回顾 2021 年立下的 flag&#xff1a; 写文章30篇 没有完成&#xff0c;技术和知识是在有断断续续学习&a…

【Linux】多线程

目录 一、什么是线程 1、线程的基本认识 2、Linux线程与接口关系的认识 3、创建线程 4、线程等待 5、线程终止 6、线程分离 二、线程的优点 三、线程的缺点 四、线程与进程的关系 1、线程安全与重入 2、不可重入情况 3、可重入情况 4、可重入与线程安全的联系 五…

算法合集 —— 数组篇

算法 —— 数组 目录算法 —— 数组1.二分查找1.1二分查找习题集2.双指针法2.1双指针法习题集3.滑动窗口3.1滑动窗口习题集4.二维数组4.1二维数组习题集1.二分查找 二分查找适用于&#xff0c;在有序排列的数组中查找某一指定元素。 其原理为范围搜索&#xff1a;如果这个元素…

opencv-python常用函数解析及参数介绍(四)——图像阈值

图像阈值处理前言1.改变图像颜色灰度图HSV图2.图像阈值图像中数值对应的效果函数与参数阈值处理效果前言 在很多任务当中&#xff0c;首要的任务就是对图像进行阈值处理&#xff0c;为后续其他操作做准备&#xff0c;本文将介绍5种阈值处理的方法以及参数设置&#xff0c;同时…

API 概述

API 概述目录概述需求&#xff1a;设计思路实现思路分析1.High-Level API &#xff1a;用于事务边界定义、控制及事务状态查询。2.2. High-Level API5.2.2 GlobalTransactionContextTransactionalTemplateLow-Level API参考资料和推荐阅读Survive by day and develop by night.…

网络协议总结

网络协议总结网络模型网络协议TCP/IP 模型网络接入层封装与解封装实际数据传输举例发送数据包接收数据包网络接口处理IP 模块处理TCP 模块处理应用程序处理网络构成通信介质与数据链路网卡二层交换机路由器 / 三层交换机![在这里插入图片描述](https://img-blog.csdnimg.cn/a8e…