小编ist*_*esi的帖子

如何在Spring MVC中配置自定义MediaType?

使用Spring MVC,我已经拥有适用于JSON和XML媒体格式的控制器。在内容协商配置中,我仅希望依靠Accept标头,并引入自定义名称媒体类型,例如:“ myXml”

我的配置:

@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer
           .favorPathExtension(false)
           .favorParameter(false)
           .ignoreAcceptHeader(false)
           .useJaf(false)
           .mediaType(MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_JSON)
           .mediaType(MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_XML)
           .mediaType("myXml", MediaType.APPLICATION_XML)
           .defaultContentType(MediaType.APPLICATION_JSON);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的控制器:

@RequestMapping(value = "/manager/{id}",
        method = RequestMethod.GET,
        produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}
)
@ResponseBody public Manager managers(@PathVariable long id){
    return repo.getManagerById(id);
}
Run Code Online (Sandbox Code Playgroud)

它工作得很好,Accept标头:application/json生成JSON,application/xml生成XML。其他任何内容均返回406不可接受,甚至myXml

我虽然期望xml ...

xml spring json spring-mvc content-negotiation

6
推荐指数
1
解决办法
7825
查看次数

Swagger和RESTful spring hateoas资源

在我的RESTful API中,所有资源都在扩展Spring的ResourceSupport基础,以便通过设计确保hateoas主体.例如:

public class PoolResource extends ResourceSupport {
    private String name;
    ...
}
Run Code Online (Sandbox Code Playgroud)

我也在使用Swagger,我想知道:是否有可能以某种方式配置swagger-ui,忽略来自ResourceSupport的属性?

在此输入图像描述

(Swagger-ui提供了一个很好且简单的API前端.作为使用Swagger的主要好处之一,API易于理解,并为那些甚至不熟悉REST API的人使用API​​.只要"链接"和"相关"进入图片.)

rest swagger spring-hateoas swagger-ui

6
推荐指数
2
解决办法
9989
查看次数

Bootstrap 3 - 将文本与网格中的表单控制项对齐

引导程序在网格中正确对齐输入和标签的正确方法是什么?

我想让标签与第一个col完全相同.看我的插:

http://plnkr.co/edit/jaMAp38Rr1g7BLW3R5AI

<div class="row">
  <div class="col-sm-6" style="border-style:solid;border-width:1px;">
    <form class="form-inline" role="form">
      <div class="form-group">
        <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email" style="width:80px;">
        <label>OK</label>
      </div>
    </form>
  </div>
  <div class="col-sm-6" style="border-style:solid;border-width:1px;">
    <form class="form-inline" role="form">
      <div class="form-group">
        <label>NOK</label>how to align it to the same as text 'OK'?
      </div>
    </form>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

css twitter-bootstrap-3

4
推荐指数
1
解决办法
3321
查看次数

如何配置Karma以包含angular-cli项目的全局scss文件?

我无法配置angular-cli + scss + karma来一起测试我的组件.运行ng testkamra单元测试仅包括组件自己的scss样式.

为了在测试中应用我的主要styles.scss,我尝试在karma.conf.js中配置它们:

files: [ 
  { pattern: './src/test.ts', watched: false },
  { pattern: './src/styles.scss' },   // main scss
  { pattern: './src/test.css' },      // just some test css to see if it is working
]
preprocessors: {
  './src/test.ts': ['@angular/cli'],
  './src/styles.scss': [ '@angular/cli' ]
}
Run Code Online (Sandbox Code Playgroud)

在业力测试期间仍未包括主要scss.但组件拥有scss和全局css.

我怎样才能使它工作?

sass karma-runner angular-cli angular

4
推荐指数
2
解决办法
5416
查看次数