侧边栏壁纸
博主头像
峰峰火火

一条咸鱼罢了

  • 累计撰写 120 篇文章
  • 累计创建 85 个标签
  • 累计收到 57 条评论

目 录CONTENT

文章目录

工具箱服务制作第一期

峰峰火火
2021-06-23 / 0 评论 / 0 点赞 / 306 阅读 / 4,005 字 / 正在检测是否收录...
温馨提示:
若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

展览

工具箱首页.png

Create Table If Not Exists `Tool`
(
    id INT(100) NOT NULL AUTO_INCREMENT COMMENT '主键',
    name VARCHAR(255) NOT NULL DEFAULT '' COMMENT '名称',
    sort INT(100) NOT NULL DEFAULT 0 COMMENT '排序',
    `timeCreated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `timeModified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最近一次修改时间',
    PRIMARY KEY (id)
);

依赖

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.0.7</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.73</version>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</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>jakarta.validation</groupId>
            <artifactId>jakarta.validation-api</artifactId>
            <version>2.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
    </dependencies>

controller


/**
 * 工具箱首页列表服务
 */
@RestController
@RequestMapping(value = "/tool")
@CrossOrigin
public class ToolController {
    @Autowired
    private ToolServiceImpl toolService;

    /**
     * 获取全部列表
     * @return
     */
    @RequestMapping(value = "",method = RequestMethod.GET)
    public ApiResponse<List<Tool>> getAll(){
        return ApiResponse.success(toolService.list());
    }

    /**
     * 新增一条列表
     * @param tool
     * @return
     */
    @RequestMapping(value = "",method = RequestMethod.POST)
    public ApiResponse<Boolean> insert(@Valid @RequestBody Tool tool){
        return ApiResponse.success(toolService.save(tool));
    }

    /**
     * 修改一条列表
     * @param toolRequest
     * @return
     */
    @RequestMapping(value = "",method = RequestMethod.PUT)
    public ApiResponse<Boolean> update(@Valid @RequestBody ToolRequest toolRequest){
        Tool tool = new Tool();
        BeanUtils.copyProperties(toolRequest,tool);
        return ApiResponse.success(toolService.updateById(tool));
    }

    /**
     * 获取一条列表
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public ApiResponse<Tool> get(@PathVariable int id){
        return ApiResponse.success(toolService.getById(id));
    }

    /**
     * 删除一条列表
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public ApiResponse<Boolean> delete(@PathVariable int id){
        return ApiResponse.success(toolService.removeById(id));
    }

    /**
     * 删除所有列表
     * @return
     */
    @RequestMapping(value = "",method = RequestMethod.DELETE)
    public ApiResponse<Boolean> deleteAll(){
        return ApiResponse.success(toolService.remove(null));
    }

}

application配置

spring:
  datasource:
    # H2 database configuration.
    driver-class-name: org.h2.Driver
    url: jdbc:h2:file:~/tools/db/test;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE
    username: admin
    password: 123456
    # 自动初始化建表
    initialization-mode: always
    # SQL 建表自动执行脚本
    schema: classpath:database/schema.sql
    # SQL
#    data: classpath:database/data.sql
  h2:
    console:
      settings:
        web-allow-others: true
      path: /h2-console
      enabled: true

mybatis-plus:
  configuration:
    map-underscore-to-camel-case: false # 数据库下划线自动转驼峰标示关闭


server.port=1234

# mybatis-plus
mybatis-plus.global-config.banner=false
mybatis-plus.global-config.db-config.id-type=auto
mybatis-plus.global-config.db-config.field-strategy=not_empty
mybatis-plus.global-config.db-config.table-underline=true
mybatis-plus.global-config.db-config.db-type=h2
mybatis-plus.global-config.db-config.logic-delete-value=1
mybatis-plus.global-config.db-config.logic-not-delete-value=0
0

评论区