是否可以返回HttpStatus状态,该状态不是来自Spring MVC中的HttpStatus枚举

时间:2017-03-21 06:24:52

标签: java spring spring-mvc http-status-codes

我想返回 555状态代码

我已经检查了Spring框架的ResponseEntity类。

我可以看到所有构造函数只接受来自HttpStatus枚举的特定代码。 这可以通过

来实现
return ResponseEntity.status(HttpStatus.CREATED).contentType(MediaType.TEXT_PLAIN).body("Custom string answer");

有没有办法像555一样返回状态代码?

2 个答案:

答案 0 :(得分:1)

你不能使用Spring ResponseEntity

来做到这一点

但是你总是可以掌握基础HttpServletResponse并做response.setStatus(555)

作为旁注,如果您的问题是"在这种情况下是否可以返回非标准HTTP代码?" ,答案可能很可能" no"

答案 1 :(得分:0)

您可以在春季完成此操作

var H = Highcharts,
    map = H.maps['countries/us/us-all'],
    chart;

// Add series with state capital bubbles
$.getJSON('https://cdn.rawgit.com/highcharts/highcharts/057b672172ccc6c08fe7dbb27fc17ebca3f5b770/samples/data/us-capitals.json', function (json) {

    var firstData = [{
    "abbrev":"AL",
    "parentState":"Alabama",
    "capital":"Montgomery",
    "lat":32.380120,
    "lon":-86.300629,
    "population":205764
  },
  {
    "abbrev":"AK",
    "parentState":"Alaska",
    "capital":"Juneau",
    "lat":58.299740,
    "lon":-134.406794,
    "population":31275
  },
  {
    "abbrev":"AZ",
    "parentState":"Arizona",
    "capital":"Phoenix",
    "lat":33.448260,
    "lon":-112.075774,
    "population":1445632
  },
  {
    "abbrev":"AR",
    "parentState":"Arkansas",
    "capital":"Little Rock",
    "lat":34.748655,
    "lon":-92.274494,
    "population":193524
  },
  {
    "abbrev":"CA",
    "parentState":"California",
    "capital":"Sacramento",
    "lat":34.268127,
    "lon": -119.255025,
    "population":4664880
  },
  {
    "abbrev":"CO",
    "parentState":"Colorado",
    "capital":"Denver",
    "lat":39.740010,
    "lon":-104.992259,
    "population":600158
  },
  {
    "abbrev":"CT",
    "parentState":"Connecticut",
    "capital":"Hartford",
    "lat":41.763325,
    "lon":-72.674069,
    "population":124775
  }];

    var secondData = [ {
    "abbrev":"DE",
    "parentState":"Delaware",
    "capital":"Dover",
    "lat":39.158035,
    "lon":-75.524734,
    "population":36047
  },
  {
    "abbrev":"FL",
    "parentState":"Florida",
    "capital":"Tallahassee",
    "lat":30.439775,
    "lon":-84.280649,
    "population":181376
  },
  {
    "abbrev":"GA",
    "parentState":"Georgia",
    "capital":"Atlanta",
    "lat":33.748315,
    "lon":-84.391109,
    "population":420003
  },
  {
    "abbrev":"HI",
    "parentState":"Hawaii",
    "capital":"Honolulu",
    "lat":21.304770,
    "lon":-157.857614,
    "population":337256
  },
  {
    "abbrev":"ID",
    "parentState":"Idaho",
    "capital":"Boise",
    "lat":43.606980,
    "lon":-116.193409,
    "population":205671
  },
  {
    "abbrev":"IL",
    "parentState":"Illinois",
    "capital":"Springfield",
    "lat":39.801055,
    "lon":-89.643604,
    "population":116250
  },
  {
    "abbrev":"IN",
    "parentState":"Indiana",
    "capital":"Indianapolis",
    "lat":39.766910,
    "lon":-86.149964,
    "population":820445
  },
  {
    "abbrev":"IA",
    "parentState":"Iowa",
    "capital":"Des Moines",
    "lat":41.589790,
    "lon":-93.615659,
    "population":203433
  },
  {
    "abbrev":"KS",
    "parentState":"Kansas",
    "capital":"Topeka",
    "lat":39.049285,
    "lon":-95.671184,
    "population":127473
  },
  {
    "abbrev":"KY",
    "parentState":"Kentucky",
    "capital":"Frankfort",
    "lat":38.195070,
    "lon":-84.878694,
    "population":25527
  }];

   var thirdData = [{
    "abbrev":"LA",
    "parentState":"Louisiana",
    "capital":"Baton Rouge",
    "lat":30.443345,
    "lon":-91.186994,
    "population":229493
  },
  {
    "abbrev":"ME",
    "parentState":"Maine",
    "capital":"Augusta",
    "lat":44.318036,
    "lon":-69.776218,
    "population":19136
  },
  {
    "abbrev":"MD",
    "parentState":"Maryland",
    "capital":"Annapolis",
    "lat":38.976700,
    "lon":-76.489934,
    "population":38394
  },
  {
    "abbrev":"MA",
    "parentState":"Massachusetts",
    "capital":"Boston",
    "lat":42.358635,
    "lon":-71.056699,
    "population":617594
  },
  {
    "abbrev":"MI",
    "parentState":"Michigan",
    "capital":"Lansing",
    "lat":42.731940,
    "lon":-84.552249,
    "population":114297
  },
  {
    "abbrev":"MN",
    "parentState":"Minnesota",
    "capital":"Saint Paul",
    "lat":44.943829,
    "lon":-93.093326,
    "population":285068
  },
  {
    "abbrev":"MS",
    "parentState":"Mississippi",
    "capital":"Jackson",
    "lat":32.298690,
    "lon":-90.180489,
    "population":173514
  },
  {
    "abbrev":"MO",
    "parentState":"Missouri",
    "capital":"Jefferson City",
    "lat":38.577515,
    "lon":-92.177839,
    "population":43079
  },
  {
    "abbrev":"MT",
    "parentState":"Montana",
    "capital":"Helana",
    "lat":46.589760,
    "lon":-112.021202,
    "population":28190
  },
  {
    "abbrev":"NE",
    "parentState":"Nebraska",
    "capital":"Lincoln",
    "lat":40.813620,
    "lon":-96.707739,
    "population":258379
  }];

    var codeData = [
    {
    "abbrev":"WA",
    "parentState":"Washington",
    "capital":"Olympia",
    "lat":47.039231,
    "lon":-122.891366,
    "population":46478
  },{
    "abbrev":"NJ",
    "parentState":"New Jersey",
    "capital":"Trenton",
    "lat":40.217875,
    "lon":-74.759404,
    "population":84913
  },
  {
    "abbrev":"NM",
    "parentState":"New Mexico",
    "capital":"Santa Fe",
    "lat":35.691543,
    "lon":-105.937406,
    "population":67947
  },
  {
    "abbrev":"NY",
    "parentState":"New York",
    "capital":"Albany",
    "lat":42.651445,
    "lon":-73.755254,
    "population":97856
  }];



    $.each(firstData, function () {
        this.z = this.population;
       // firstData.push(this);
    });

   /**  $.each(json.splice(8,15), function (k, v) {
        secondData.push(v);
    });
     $.each(json.splice(16, 20), function (k, v) {
        thirdData.push(v);
    }); */

    chart = Highcharts.mapChart('container', {


        title: {
            text: 'Highmaps lat/lon demo'
        },

        tooltip: {
            pointFormat: '{point.capital}, {point.parentState}<br>' +
                'Lat: {point.lat}<br>' +
                'Lon: {point.lon}<br>' +
                'Population: {point.population}'
        },

        xAxis: {
            crosshair: {
                zIndex: 5,
                dashStyle: 'dot',
                snap: false,
                color: 'gray'
            }
        },

        yAxis: {
            crosshair: {
                zIndex: 5,
                dashStyle: 'dot',
                snap: false,
                color: 'gray'
            }
        },



        series: [{
            name: 'Basemap',
            mapData: map,
            borderColor: '#606060',
            nullColor: 'rgba(200, 200, 200, 0.2)',
            showInLegend: false
        }, {
            name: 'Separators',
            type: 'mapline',
            data: H.geojson(map, 'mapline'),
            color: '#101010',
            enableMouseTracking: false,
            showInLegend: false
        }, {
            type: 'mapbubble',
            dataLabels: {
                enabled: true,
                format: '{point.parentState}',
             //   allowOverlap: true
            },
            name: 'Radius/Region',
            data: firstData,
          //  maxSize: '12%',
            color: H.getOptions().colors[0]
        }, 
       {
            type: 'mappoint',
            dataLabels: {
                enabled: true, 
                color:'red',
                format: '{point.capital}',
             //  allowOverlap: true
            },
            name: 'Location',
            data: secondData,
           // maxSize: '12%',
            color: H.getOptions().colors[5],
            marker: {
            symbol: 'url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOIAAADfCAMAAADcKv+WAAAAkFBMVEX////8Bwf8AAD//Pz/8vL+zc3/5eX/+fn/9vb+trb+wMD/4uL+ysr+xcX+1NT8Kir/7Oz9c3P9goL9jY39Y2P+urr+p6f+pKT+oKD+2dn8MTH8QUH9V1f9iYn+sLD9mJj9b2/8ISH9Skr9enr8GRn8Ojr9mZn9VVX9Z2f8ERH9T0/8Li79jIz9XV38PT39bGwvLcFgAAAJiklEQVR4nN2d20IiMQyGaRBRFFBQBBQ5ioIrvv/b7RwAB5hOk0zTFv7L3bX2257SJM1UKhwNNtesnzsfjQCmVd+dkNTVK4CCW9/dEFQrAlQKPnz3Q07NhFABXOxqvE0JI8Z3310RUn9HqODNd19ktNwBxoy+OyOicYZQwb3v7gjogFBB13d/7Gt5QKhg7btD1nU4hvGxceO7S5Z1TBgxNn33ya6WJ4SXthhPx/DSbLg8wmgxPvjulz318wgvajHmjmGMOPLdM1vK2Wm2iN++u2ZJmlma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RYl2m+KTEsUN3YOOwUzo0GA3mvQiZdXE3eQsELE1rF7DaXKd83RbI2sHcReg31yChM8YaTmRh4S4BVVEwG519Artd+vJe/LcZcULusMWcOXVYt+0BF1fcxxxg3SNUycpXtVb2cylAAbbCWrLxxhie8J3I0/7FNi52gF+0yh7BcTBqOVVcpoH8XfM1DF7bizNKtaZ2GLMjrrCbVlUBVDbGWSDsYbC5QAU0oeHeoVps1c2euXWTn/cvTDfdKNH+P9tv0k6Op5vuJiRj82ooUBMClSuX6ashq8rDmUAI9E11TV7K8BsQfPV81RmxQUif7pI9nFaM7kE87Lv7nvfgKOE+gjWMGY3+DgoWy11X8aGjCjv5yOOQFHY/kld6XNHlq9eTptj1nTP3niBW6M0xTa7tJEEl3XnruT9RSyUq9PY25VVeNuCjM/2WnVev3qrtZoNJv3tcFNibCbaTcFG0abXxkO/QBfjVBlCNKEUVW4lAzp+/DqeKMRUOG3MwJ9o0ZTYWYGBF/BBaHCkDdMw3uCR1dRZkZQBXfZKghDgf/PCNhQwSNvAEdJr8LS1+mBxSUsw6J0TPjw8JpAQtoP2IRXUJgpXQQDgi9Mg5UugnER530qjeUGq7BKl5dQ/j0Y4NP7e0lryo1gXMDd8E95EQy4hJvTXnkRDDlfsBed2jUAkws57lOd2DXRHD17/8Wh1nAEOAyq3oUFNY68zOpiDvu9snuN5wfnQsqk8kVTNNBCUKW0N07jHNXLuPgeawI7wMmF7aI7xfVqk+zb/kWdg1nFN4zhLzpV/Az1H1ZXi/qXXosUAAAAAElFTkSuQmCC)',
             height:'3%',
                width:'3%'
               }
        },
        {
            type: 'mappoint',
            dataLabels: {
                enabled: true, 
                color:'blue',
                format: '{point.capital}',
             //  allowOverlap: true
            },
            name: 'Zipcode',
            data: thirdData,
           // maxSize: '12%',
            color: H.getOptions().colors[5],
            marker: {
                symbol: 'url(https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSiP748HIe4gEauazvJPbxdRpGHHTffgkyZDD7DG7wLqJkVkHzd)',
                height:'3%',
                width:'3%'
            }
        },
        {
            allAreas: false,
            dataLabels: {
                enabled: true,
                format: '{point.parentState}'
            },
            name:'States',
            data: codeData,
            mapData: Highcharts.maps['countries/us/us-all'],
            joinBy: ['postal-code', 'abbrev'],
            color: H.getOptions().colors[7]
        }
       ]
    });

 });

// Display custom label with lat/lon next to crosshairs
$('#container').mousemove(function (e) {
    var position;
    if (chart) {
        if (!chart.lab) {
            chart.lab = chart.renderer.text('', 0, 0)
                .attr({
                    zIndex: 5
                })
                .css({
                    color: '#505050'
                })
                .add();
        }

        e = chart.pointer.normalize(e);
        position = chart.fromPointToLatLon({
            x: chart.xAxis[0].toValue(e.chartX),
            y: chart.yAxis[0].toValue(e.chartY)
        });

        chart.lab.attr({
            x: e.chartX + 5,
            y: e.chartY - 22,
            text: 'Lat: ' + position.lat.toFixed(2) + '<br>Lon: ' + position.lon.toFixed(2)
        });
    }
});

$('#container').mouseout(function () {
    if (chart && chart.lab) {
        chart.lab.destroy();
        chart.lab = null;
    }
});