Git Product home page Git Product logo

web-packing's Introduction

web添加包装类

安装

mvn install
<dependency>
  <groupId>io.github.yanfeiwuji</groupId>
  <artifactId>web-packing</artifactId>
  <version>0.0.1-RELEASE</version>
</dependency>

添加你的返回类

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author yanfeiwuji
 */
@Data
@AllArgsConstructor
public class R<T> {
  boolean success;
  String msg;
  T data;

  public static <T> R<T> OK(T data) {
    return new R<>(true, "success", data);
  }
}

配置

package com.yfwjt.test;

import io.github.yanfeiwuji.web.packing.ObjToPacking;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;


@SpringBootApplication
@RestController
@RequestMapping
public class SpringDemoApplication {

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

  @Bean
  ObjToPacking<R> objToPacking() {
    return o -> R.OK(o);
  }

  @GetMapping("/pack")
  public R<List<String>> pack() {
    return R.OK(Collections.singletonList("123"));
  }

  @GetMapping("/doPack")
  public List<String> noPdoPack() {
    return Collections.singletonList("123");
  }

  @GetMapping("/noPack")
  @NoPacking
  public List<String> noPack() {
    return Collections.singletonList("123");
  }



}

效果

url http://localhost:3801/pack url http://localhost:3801/noPack

{
    "success": true,
    "msg": "success",
    "data": [
        "123"
    ]
}

web-packing's People

Contributors

yanfeiwuji avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.