springboot通过controller,dao,service,serviceImpl的基类快速实现各个实体类的增删改查分页等操作

news2024/11/19 1:43:10

1.pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.lz</groupId>
    <artifactId>hehuorenservice</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>hehuorenservice</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <!-- 排除掉logging,不使用logback,改用log4j2 -->
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.0</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.24</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.9</version>
        </dependency>
        <!--引入swagger-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.7.0</version>
        </dependency>
        <!-- 验证参数 -->
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.1.Final</version>
        </dependency>

        <!--  validation-api 需要依赖hibernate validator-->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>6.0.16.Final</version>
        </dependency>

        <!--引入面向切面依赖包-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>

        <!-- log4j2 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>


        <!--引入热启动依赖包-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>

                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

2.application.yml

server:
  port: 8888
spring:
  datasource:
    druid:
      # 数据库访问配置, 使用druid数据源
      username: root
      password: 123456
      url: jdbc:mysql://localhost:3306/homedecoration?useSSL=false&useUnicode=true&characterEncoding=UTF-8
      driver-class-name: com.mysql.cj.jdbc.Driver
      type: com.alibaba.druid.pool.DruidDataSource
mybatis:
  # 实体类的路径
  type-aliases-package: com.lz.homedecoration.entity
  #映射的mysql的mapper的xml文件目录
  mapper-locations: classpath:/mapper/*.xml

3.目录结构如下:

在这里插入图片描述

3.建表:

CREATE TABLE `user` (
  `id` int(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(30) DEFAULT NULL,
  `password` varchar(30) DEFAULT NULL,
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

4.目录代码如下:

4.1 自定义异常类:

在这里插入图片描述

package com.lz.homedecoration.common.bean;

public class CustomException extends RuntimeException {
    public CustomException(String message) {
        super(message);
    }
}

4.2 自定义分页实体类:

在这里插入图片描述

package com.lz.homedecoration.common.bean;

import java.util.List;

public class PageResult<T> {
    private List<T> list;
    private long count;

    public PageResult(List<T> list, long count) {
        this.list = list;
        this.count = count;
    }

    public PageResult() {

    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public long getCount() {
        return count;
    }

    public void setCount(long count) {
        this.count = count;
    }
}

4.3 swagger配置类:

在这里插入图片描述

package com.lz.homedecoration.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket buildDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(buildApiInf())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.lz.homedecoration"))
                .paths(PathSelectors.any())
                .build();
    }
    private ApiInfo buildApiInf() {
        return new ApiInfoBuilder()
                .title("系统API文档")
                .contact(new Contact("hong", "/", "10000@qq.com"))
                .version("1.0")
                .build();
    }
}

4.4 controller的基类:

在这里插入图片描述

package com.lz.homedecoration.common.controller;

import com.lz.homedecoration.common.bean.PageResult;
import com.lz.homedecoration.common.request.PageReq;
import com.lz.homedecoration.common.response.ResultRes;
import com.lz.homedecoration.entity.User;
import org.springframework.web.bind.annotation.*;

import java.util.List;

public abstract class BaseController<T> {

    @GetMapping("/list")
    public abstract ResultRes list();

    @GetMapping("/get/{id}")
    public abstract ResultRes get(@PathVariable Long id);

    @PostMapping("/add")
    public abstract ResultRes add(@RequestBody User user);

    @RequestMapping(value = "/update",method = RequestMethod.PATCH)
    public abstract ResultRes update(@RequestBody User user);

    @RequestMapping(value = "/delete/{id}",method = RequestMethod.DELETE)
    public abstract ResultRes delete(@PathVariable Long id) throws Exception;

    @PostMapping("/pageList")
    public abstract ResultRes pageList(@RequestBody PageReq pageReq);
}

4.5 dao的基类:

在这里插入图片描述

package com.lz.homedecoration.common.dao;

import com.lz.homedecoration.common.request.PageReq;

import java.io.Serializable;
import java.util.List;

public interface BaseDao<T,PK extends Serializable> {
    List<T> list();
    T get(PK id);
    int add(T t);
    int delete(PK id);
    int update(T t);
    List<T> page(PageReq<T> t);
    long count(PageReq<T> t);
}

4.6 ControllerAdvice异常拦截类:

在这里插入图片描述

package com.lz.homedecoration.common.exception;

import com.lz.homedecoration.common.response.ResultRes;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionHandle {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResultRes exceptionHandle(Exception e){
        return  ResultRes.fail(e.getMessage());
    }
}

4.7 分页入参类封装:

在这里插入图片描述

package com.lz.homedecoration.common.request;
public class PageReq<T> {
    private T parameter;
    private long page;
    private long pageSize;
    private long startRow;

    public T getParameter() {
        return parameter;
    }

    public void setParameter(T parameter) {
        this.parameter = parameter;
    }

    public long getPage() {
        if(page<=0){
            this.setPage(1);
        }
        return page;
    }

    public void setPage(long page) {
        this.page = page;
    }

    public long getPageSize() {
        if(pageSize==0){
            this.setPageSize(10);
        }
        return pageSize;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    public long getStartRow() {
        return (this.page-1)*pageSize;
    }

    public void setStartRow(long startRow) {
        this.startRow = startRow;
    }
}

4.8 接口响应结果类:

在这里插入图片描述

package com.lz.homedecoration.common.response;

import lombok.Data;

@Data
public  class ResultRes {
    private Object data;
    private String message;
    private int code;

    public ResultRes(Object data, String message, int code) {
        this.data = data;
        this.message = message;
        this.code = code;
    }

    public static ResultRes success(Object data, String message, int code){
        ResultRes resultRes = new ResultRes(data,message,code);
        return  resultRes;
    }
    public static ResultRes success(Object data,String message){
        ResultRes resultRes = new ResultRes(data,message,1);
        return  resultRes;
    }
    public static ResultRes success(Object data){
        ResultRes resultRes = new ResultRes(data,"操作成功",1);
        return  resultRes;
    }
    public static ResultRes success(){
        ResultRes resultRes = new ResultRes(null,"操作成功",1);
        return  resultRes;
    }
    public static ResultRes fail(Object data,String message, int code){
        ResultRes resultRes = new ResultRes(data,message,code);
        return  resultRes;
    }
    public static ResultRes fail(Object data,String message){
        ResultRes resultRes = new ResultRes(data,message,0);
        return  resultRes;
    }
    public static ResultRes fail(Object data){
        ResultRes resultRes = new ResultRes(data,"操作失败",0);
        return  resultRes;
    }
    public static ResultRes fail(){
        ResultRes resultRes = new ResultRes(null,"操作失败",0);
        return  resultRes;
    }
}

4.9 service基类:

在这里插入图片描述

package com.lz.homedecoration.common.service;

import com.lz.homedecoration.common.bean.PageResult;
import com.lz.homedecoration.common.request.PageReq;

import java.io.Serializable;
import java.util.List;

public interface BaseService<T,PK extends Serializable> {
    List<T> list();
    T get(PK id);
    int add(T t);
    int delete(PK id);
    int update(T t);
    PageResult<T> pageList(PageReq<T> pageReq);
}

4.10 serviceImpl基类封装:

在这里插入图片描述

package com.lz.homedecoration.common.service.impl;

import com.lz.homedecoration.common.bean.PageResult;
import com.lz.homedecoration.common.dao.BaseDao;
import com.lz.homedecoration.common.request.PageReq;
import com.lz.homedecoration.common.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

public class BaseServiceImpl<T, PK extends Serializable> implements BaseService<T, PK> {
    @Autowired
    BaseDao<T, PK> baseDao;

    public List<T> list() { return baseDao.list(); }
    @Override
    public T get(PK id) {
        return (T) baseDao.get(id);
    }

    @Override
    public int add(T t) {
        return baseDao.add(t);
    }

    @Override
    public int delete(PK id) {
        return baseDao.delete(id);
    }

    @Override
    public int update(T t) {
        return baseDao.update(t);
    }

    @Override
    public PageResult<T> pageList(PageReq<T> pageReq) {
        PageResult<T> pageResult = new PageResult<T>();
        pageResult.setList(baseDao.page(pageReq));
        long count = baseDao.count(pageReq);
        pageResult.setCount(count);
        return pageResult;
    }


}

4.11 日志打印工具类:

在这里插入图片描述

package com.lz.homedecoration.common.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CommonLogUtil {
    public static Logger logger = LoggerFactory.getLogger(CommonLogUtil.class);
}

4.12 用户的controller层,基础controller的基类并实现实基类的实现。

在这里插入图片描述

package com.lz.homedecoration.controller;

import com.lz.homedecoration.common.bean.PageResult;
import com.lz.homedecoration.common.controller.BaseController;
import com.lz.homedecoration.common.request.PageReq;
import com.lz.homedecoration.common.response.ResultRes;
import com.lz.homedecoration.entity.User;
import com.lz.homedecoration.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.lz.homedecoration.common.util.CommonLogUtil;
@RestController
@RequestMapping("/user")
@Api(value = "用户")
public class UserController extends BaseController<User> {

    @Autowired
    UserService userService;

    @ApiOperation(value = "获取用户列表", notes = "获取用户列表")
    @Override
    public ResultRes list() {
        return ResultRes.success(userService.list());
    }

    @ApiOperation(value = "获取用户信息", notes = "根据用户id获取用户信息")
    @ApiImplicitParam(name = "id", value = "用户id", required = true, dataType = "Long", paramType = "path")
    @Override
    public ResultRes get(@PathVariable Long id) {
        User user = userService.get(id);
        return ResultRes.success(user);
    }

    @Override
    public ResultRes add(@RequestBody User user) {
        userService.add(user);
        return ResultRes.success();
    }

    @Override
    public ResultRes update(@RequestBody User user) {
        userService.update(user);
        return ResultRes.success();
    }

    @Override
    public ResultRes delete(@PathVariable Long id) {
       int count = userService.delete(id);
       if(count !=0){
           return ResultRes.success();
       }else {
           CommonLogUtil.logger.info("---------没有相关id: "+id+"的数据-------------");
           throw new RuntimeException("没有相关id: "+id+"的数据");
       }
    }

    @Override
    public ResultRes pageList(@RequestBody PageReq pageReq) {
        PageResult<User> pageResult = userService.pageList(pageReq);
        return ResultRes.success(pageResult);
    }

}

4.13 用户的dao类继承dao的基类:

在这里插入图片描述

package com.lz.homedecoration.dao;

import com.lz.homedecoration.common.dao.BaseDao;
import com.lz.homedecoration.entity.User;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface UserDao extends BaseDao<User,Long> {
}

4.14 用户实体类:

在这里插入图片描述

package com.lz.homedecoration.entity;

import lombok.Data;
import java.io.Serializable;

@Data
public class User implements Serializable {
    int id;
    String name;
    String password;
    String createTime;
    String updateTime;
}

4.15 用户的service层继承service的基类:

在这里插入图片描述

package com.lz.homedecoration.service;

import com.lz.homedecoration.common.service.BaseService;
import com.lz.homedecoration.entity.User;


public interface UserService extends BaseService<User,Long> {
}

4.16 用户的实现类serviceImpl继承对应的serviceImpl基类的方法:

在这里插入图片描述

package com.lz.homedecoration.service.impl;

import com.lz.homedecoration.common.service.impl.BaseServiceImpl;
import com.lz.homedecoration.entity.User;
import com.lz.homedecoration.service.UserService;
import org.springframework.stereotype.Service;


@Service
public class UserServiceImpl extends BaseServiceImpl<User,Long> implements UserService {

}

4.17 springboot的应用主类:

在这里插入图片描述

package com.lz.homedecoration;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/** @author Administrator */
@SpringBootApplication
@MapperScan(basePackages = {"com.lz.homedecoration.dao"}) // 配置dao类的扫码路径
public class HomeDecorationApplication {

  public static void main(String[] args) {
    SpringApplication.run(HomeDecorationApplication.class, args);
  }
}

4.18 user的mapper.xml的编写:

在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lz.homedecoration.dao.UserDao">
    <resultMap id="userMap" type="com.lz.homedecoration.entity.User">
        <result property="id" column="id" jdbcType="INTEGER"></result>
        <result property="name" column="name" jdbcType="VARCHAR"></result>
        <result property="password" column="password" jdbcType="VARCHAR"></result>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"></result>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"></result>
    </resultMap>

    <select id="list" resultMap="userMap">
        select * from user
    </select>
    <select id="get" resultMap="userMap">
        select * from user where id=#{id}
    </select>
    <select id="page" resultMap="userMap">
        select * from user
        <trim prefix="where" suffixOverrides="and">
            <include refid="listWhere"></include>
        </trim>
        <if test="page!=null and pageSize!=null">
            <![CDATA[LIMIT #{startRow},#{pageSize} ]]>
        </if>
    </select>
    <select id="count" resultType="Long">
        select count(1) from user
        <trim prefix="where" suffixOverrides="and">
            <include refid="listWhere"></include>
        </trim>
    </select>


    <insert id="add" parameterType="com.lz.homedecoration.entity.User">
        insert into user (
        <trim suffixOverrides=",">
            <if test="name !=null">name,</if>
            <if test="password !=null">password,</if>
            <if test="createTime !=null">createTime,</if>
            <if test="updateTime !=null">updateTime,</if>
        </trim>
        ) values (
        <trim prefixOverrides="," suffixOverrides=",">
            <if test="name !=null">#{name,jdbcType = VARCHAR},</if>
            <if test="password !=null">#{password,jdbcType = VARCHAR},</if>
            <if test="createTime !=null">#{createTime,jdbcType = TIMESTAMP},</if>
            <if test="updateTime !=null">#{updateTime,jdbcType = TIMESTAMP},</if>
        </trim>
        )
    </insert>
    <update id="update" parameterType="com.lz.homedecoration.entity.User">
        update user
        <trim prefix="set" suffixOverrides=",">
            <if test="name !=null">name = #{name,jdbcType = VARCHAR},</if>
            <if test="password !=null">password = #{password,jdbcType = VARCHAR},</if>
            <if test="createTime !=null">createTime = #{createTime,jdbcType = TIMESTAMP},</if>
            <if test="updateTime !=null">updateTime = #{updateTime,jdbcType = TIMESTAMP},</if>
        </trim>
        <where>
            id=#{id}
        </where>
    </update>
    <delete id="delete">
        delete from  user  where id= #{id}
    </delete>
    <sql id="listWhere">
        <if test="parameter !=null">
            <if test="parameter.name !=null">name = #{parameter.name,jdbcType = VARCHAR} and</if>
            <if test="parameter.password !=null">password = #{parameter.password,jdbcType = VARCHAR} and</if>
            <if test="parameter.createTime !=null">createTime = #{parameter.createTime,jdbcType = TIMESTAMP} and</if>
            <if test="parameter.updateTime !=null">updateTime = #{parameter.updateTime,jdbcType = TIMESTAMP} and</if>
        </if>
    </sql>

</mapper>

源码:
https://gitee.com/hyhshy/base.git

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

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

相关文章

【1】K8s上部署KubeSphere

目录 1、环境初始化 【1】改名字和主机名解析 【2】时间同步 【3】禁用iptables和firewalld服务&#xff08;三台都要设置&#xff09; 【4】禁用selinux&#xff08;三台都要设置&#xff09; 【5】禁用swap分区 【6】修改linux的内核参数 2、安装docker 【1】安装doc…

化学试剂Silane-PEG-Biotin,硅烷聚乙二醇生物素材料说明

英文名称&#xff1a;Biotin-PEG-Silane 中文名称&#xff1a;生物素-聚乙二醇-硅烷 分子量&#xff1a;1k&#xff0c;2k&#xff0c;3.4k&#xff0c;5k&#xff0c;10k&#xff0c;20k。。。 存储条件&#xff1a;-20C&#xff0c;避光&#xff0c;避湿 用 途&#xff…

RS485 TO ETH (B)无法联网怎么解决?

1 设置下静态IP&#xff0c;例如&#xff1a; RS485 TO ETH (B) 设置为 192.168.1.200 端口号1111&#xff1b; 电脑设置为192.168.1.199 端口号1111&#xff1b; 2 用互联网社区分享的TCP服务器测试下&#xff1a;120.79.100.197 端口号 10002 3 请关闭电脑的所有防火墙&am…

Java 中 List 排序的 3 种方法

在某些特殊的场景下&#xff0c;我们需要在 Java 程序中对 List 集合进行排序操作。比如从第三方接口中获取所有用户的列表&#xff0c;但列表默认是以用户编号从小到大进行排序的&#xff0c;而我们的系统需要按照用户的年龄从大到小进行排序&#xff0c;这个时候&#xff0c;…

1.1.1信号的概念、描述及分类

目录 1.信号的概念 2.描述 3.分类 3.1确定信号和随机信号 ​3.2连续信号和离散信号​​​​​​​ 两者之间存在这样一种关系 3.3周期信号和非周期信号 3.4能量信号和功率信号 一些例题 1.信号的概念 信号是表示消息的 物理量 &#xff0c;如电信号可以通过 幅度 、 …

23.指针数组的概念,定义方法

1.二维数组 二维数组有行有列&#xff0c;二维数组可以看成由多个一维数组构成的&#xff0c;是多个一维数组的集合&#xff0c;可以认为二维数组的每一个元素都是一个一维数组。 #include<stdio.h> int main() {int a[3][5];printf("a%p\n",a);printf("…

Zabbix与乐维监控对比分析(八)——其他功能篇

前面我们详细介绍了Zabbix与乐维监控的架构与性能、Agent管理、自动发现、权限管理、对象管理、告警管理、可视化、图形图表及网络功能方面的对比分析&#xff0c;接下来我们将对二者其他功能进行对比分析。 本篇是Zabbix与乐维监控对比分析专题系列文章的第八篇&#xff0c;也…

Visual Studio Code快捷键的使用-RK3568开发

在 Visual Studio Code 软件中使用快捷键可以增加自身的效率&#xff0c;一些常用的快捷键如下所 示&#xff1a; F1 打开可以输入命令 F2 重命名变量&#xff0c;方便重构 F5 运行和调试代码 F12 去到定义的地方 shiftF12 查找所有引用 ctrlg 会让你输入数字&#xff0c;快速定…

SpringBoot2源码1-嵌入式Tomcat启动和@SpringBootApplication注解原理

1. 测试案例 1.1 引入依赖 <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc --> <dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.3.5</ve…

看完RabbitMQ了的几种消息模型,我对RabbitMQ有了新的认识

前言&#xff1a;大家好&#xff0c;我是小威&#xff0c;24届毕业生&#xff0c;曾经在某央企公司实习&#xff0c;目前在某税务公司。前面已经记录了两种消息模型知识&#xff0c;因此本篇文章将记录和分享剩下的RabbitMQ几种消息模型相关知识点。 本篇文章记录的基础知识&am…

锁策略和synchronized

1.常见的锁策略&#xff08;1&#xff09;乐观锁 和 悲观锁乐观锁&#xff1a;预测锁竞争的情况不激烈&#xff08;工作量较少&#xff09;悲观锁&#xff1a;预测锁竞争的情况很激烈&#xff08;工作量较多&#xff09;&#xff08;2&#xff09;轻量级锁 和 重量级锁轻量级锁…

IDEA Alibaba代码格式化(EclipseCodeFormatter)

1.阿里模板下载地址https://github.com/alibaba/p3c/tree/master/p3c-formatter2.下载阿里配置文件&#xff08;eclipse-codestyle.xml&#xff09;&#xff0c;因为此文件是针对ecplice的&#xff0c;在IDEA中使用配置文件&#xff0c;需要安装Eclipse Code Formatter插件3.配…

文档控件 Aspose.PDF for Java 授权须知

Aspose.PDF是一款高级PDF处理API&#xff0c;可以在跨平台应用程序中轻松生成&#xff0c;修改&#xff0c;转换&#xff0c;呈现&#xff0c;保护和打印文档。无需使用Adobe Acrobat。此外&#xff0c;API提供压缩选项&#xff0c;表创建和处理&#xff0c;图形和图像功能&…

马蹄集 卡罗尔数

卡罗尔数 难度&#xff1a;白银 0时间限制&#xff1a;1秒 巴占用内存&#xff1a;64M 卡罗尔数是其值满足4n-2(n1)-1的整数(n为正整数)。输入正整 数N判断它是不是卡罗尔数&#xff0c;输出YES或者NO。 #include <bits/stdc.h>> using namespace std; int main(…

SpringMVC超详解

SpringMVC超详解1、SpringMVC简介1.1、什么是MVCMVC是一种软件架构的思想&#xff0c;将软件按照模型、视图、控制器来划分M&#xff1a;Model&#xff0c;模型层&#xff0c;指工程中的JavaBean&#xff0c;作用是处理数据JavaBean分为两类&#xff1a;一类称为实体类Bean&…

算法拾遗二十四之暴力递归到动态规划二

算法拾遗二十四之暴力递归到动态规划二背包问题一优化题目二优化题目三&#xff08;贴纸拼词&#xff09;优化题目四&#xff1a;最长公共子序列优化背包问题一 weights[i]和values[i]的值都是大于等于0的&#xff0c;不存在负数的情况。 可以从尝试入手&#xff0c;改动态规划…

基于智能矿山电力监控系统的设计与应用方法

摘要&#xff1a;随着煤矿建设的智能化程度越来越高&#xff0c;构建智能电力监控系统实现对矿山生产的有效监控至关重要。首先分析了矿山电力监控系统存在的主要问题&#xff0c;其次重点介绍了基于智能矿山电力监控系统的设计过程&#xff0c;后提出了加强智能电力监控系统的…

Inspur KOS 龙蜥衍生版面向智慧新媒体转型的探索与实践 | 龙蜥案例

编者按&#xff1a;日前&#xff0c;龙蜥社区理事单位浪潮信息正式对外发布基于龙蜥操作系统&#xff08;Anolis OS&#xff09;的服务器操作系统 Inspur KOS&#xff0c;并基于 Inspur KOS 推出可视化迁移方案 C2K&#xff0c;该方案能够将用户应用安全可靠地切换到 Inspur KO…

【系列02】Java流程控制 scanner 选择结构 循环结构语句使用 [有目录]

Scanner输入 Next和NextLine区别 NextLine 用的会多点 因为Next遇到空格就断开了 next语法使用 package com.SunAo.scanner; import java.util.Scanner; public class Demo01 {public static void main(String[] args) {//创建扫描器用来接收 键盘输入Scanner scanner new …

李宏毅ML-批次与动量

批次与动量 文章目录批次与动量1. Small batch or Large batch?2. Gradient descent Momentum3. 总结1. Small batch or Large batch? 在使用 gradient descent 进行 optimization 时&#xff0c;在每一次 epoch 前&#xff0c;要 shuffle 所有的资料&#xff0c;然后再分成…