20200318——十次方 项目搭建 二

搭建父工程
父工程的作用,主要就是给子工程提供依赖,不需要有src下面的代码
在这里插入图片描述
子模块common
里面是新建实体类Result,封装了前端返回后端的信息

在这里插入图片描述

idWorker是雪花算法,用来标识id的,分布式id生成器
在这里插入图片描述
基础的CRUD模块base
在这里插入图片描述
新增异常

package com.mmz.base.controller;

import entity.Result;
import entity.StatusCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Classname BaseExceptionHandler
 * @Description TODO
 * @Date 2020/3/18 22:15
 * @Created by mmz
 */
@RestControllerAdvice
public class BaseExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public Result exception(Exception e) {
        e.printStackTrace();
        return new Result(false, StatusCode.ERROR,e.getMessage());
    }
}

Controller层

package com.mmz.base.controller;

import com.mmz.base.pojo.Label;
import com.mmz.base.service.LabelService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.persistence.Id;

/**
 * @Classname BaseController
 * @Description TODO
 * @Date 2020/3/18 20:04
 * @Created by mmz
 */
@RestController
@CrossOrigin
@RequestMapping("/label")
public class LabelController {

    @Autowired
    private LabelService labelService;

    @RequestMapping(method = RequestMethod.GET)
    public Result findAll(){
        return new Result(true, StatusCode.OK,"查询成功",labelService.findAll());
    }

    @RequestMapping(method = RequestMethod.GET,value = "/{labelId}")
    public Result findById(@PathVariable String labelId){
        return new Result(true, StatusCode.OK,"查询成功",labelService.findById(labelId));
    }

    @RequestMapping(method = RequestMethod.POST)
    public Result save(@RequestBody Label label){
        labelService.save(label);
        return new Result(true, StatusCode.OK,"添加成功");
    }

    @RequestMapping(method = RequestMethod.PUT,value = "/{labelId}")
    public Result update(@RequestBody Label label,@PathVariable String labelId){
        label.setId(labelId);
        labelService.update(label);
        return new Result(true, StatusCode.OK,"更新成功");
    }


    @RequestMapping(method = RequestMethod.DELETE,value = "/{labelId}")
    public Result deleteById(@PathVariable String labelId){
        labelService.delete(labelId);
        return new Result(true, StatusCode.OK,"删除成功");
    }

}

配置文件yml

server:
  port: 9001

spring:
  application:
    name: tensquare-base
  datasource:
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://192.168.174.128:3306/tensquare_base?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
    username: root
  jpa:
    database: mysql
    show-sql: true
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值