小编Sho*_*ham的帖子

Java Spring Boot:如何将我的应用程序根目录("/")映射到index.html?

我是Java和Spring的新手.如何将我的应用程序根映射http://localhost:8080/到静态index.html?如果我导航到http://localhost:8080/index.html它的工作正常.

我的app结构是:

迪尔斯

config\WebConfig.java看起来像这样:

@Configuration
@EnableWebMvc
@ComponentScan
public class WebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("/");
        }
}
Run Code Online (Sandbox Code Playgroud)

我试图添加registry.addResourceHandler("/").addResourceLocations("/index.html");但它失败了.

java spring spring-boot

121
推荐指数
9
解决办法
15万
查看次数

如何在Protobuf服务rpc中返回一个数组

我的.proto文件中有以下架构:

service MyService {
    rpc GetItem (ItemQuery) returns (Item) {
    }
}

message ItemQuery {
    int id = 1;
}
message Item {
    int id = 1;
    string name = 2;
}
Run Code Online (Sandbox Code Playgroud)

现在我想添加另一个rpc方法来返回多个Items.像这样的东西:

rpc GetItems (ItemsQuery) returns (repeated Item) {
}
Run Code Online (Sandbox Code Playgroud)

有没有比定义Items消息更好的方法呢?

rpc protocol-buffers

26
推荐指数
1
解决办法
1万
查看次数

ASPNETCOMPILER(0,0):错误ASPRUNTIME:对象引用未设置为对象的实例

我正在尝试使用Visual Studio 2013发布网站.我收到一个错误:

ASPNETCOMPILER(0,0):错误ASPRUNTIME:对象引用未设置为对象的实例.

它也发生在Visual Studio 2010上.我试图重启VS和PC.我*.dll.refresh从bin目录中删除了.<clear/>我的web.config中没有标签.我想这一切都始于我意外删除了我的*.suo文件.

有任何想法吗?

更新:

我只是注意到只有当我尝试预编译我的网站时才会发生这种情况.如果我发布没有预编译它工作正常...

c# asp.net publish visual-studio

8
推荐指数
2
解决办法
8269
查看次数

spring boot setContentType不起作用

我试图在spring-boot上返回一个图像(1.2.2)
我应该如何设置内容类型?以下不适用于我(意味着响应标头根本不包含'content-type'标头):

    @RequestMapping(value = "/files2/{file_name:.+}", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> getFile2(final HttpServletResponse response) throws IOException {
    InputStream is = //someInputStream...
    org.apache.commons.io.IOUtils.copy(is, response.getOutputStream());
    response.setContentType("image/jpeg");
    InputStreamResource inputStreamR = new InputStreamResource(is);
    return new ResponseEntity<>(inputStreamR, HttpStatus.OK);
}

@RequestMapping(value = "/files3/{file_name:.+}", method = RequestMethod.GET)
public HttpEntity<byte[]> getFile3() throws IOException {
    InputStream is = //someInputStream...
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_JPEG);
    return new HttpEntity<>(IOUtils.toByteArray(is), headers);
}
Run Code Online (Sandbox Code Playgroud)

spring content-type spring-boot

7
推荐指数
2
解决办法
8439
查看次数

Spring Boot - 返回日期(不是时间戳)

我正在使用Spring-Boot 1.2.2和这段代码:

@RequestMapping(value = "/dates", method = RequestMethod.GET)
public Date getDates() {
    return new Date();
}
Run Code Online (Sandbox Code Playgroud)

返回此响应:

1433241315047
Run Code Online (Sandbox Code Playgroud)

我怎样才能让它回归"Sun May 31 16:26:43 IDT 2015"?我在谷歌上发现了一些例子,mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false)但无法弄清楚我应该在哪里写这个......

更新:
我向pom.xml添加了2个依赖项:

<dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-joda</artifactId>
        <version>2.4.0</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

并添加spring.jackson.date-format=yyyy-MM-ddapplication.properties 仍然获取时间戳,所以我开始消除所有不必要的代码,发现删除@Configuration我的注释WebConfiguration.java解决了这个问题:

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

@Configuration
@EnableWebMvc
@ComponentScan
public class WebConfiguration extends WebMvcConfigurerAdapter {

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>>     httpMessageConverters) {

        httpMessageConverters.add(new …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

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

SQLAlchemy JSON列-如何执行包含查询

我在mysql(5.7.12)中有下表:

class Story(db.Model):
    sections_ids = Column(JSON, nullable=False, default=[])
Run Code Online (Sandbox Code Playgroud)

sections_ids是basicly整数[1,2,...,N]的列表。我需要获取sections_ids包含X的所有行。我尝试了以下操作:

stories = session.query(Story).filter(
        X in Story.sections_ids
    ).all()
Run Code Online (Sandbox Code Playgroud)

但它抛出:

NotImplementedError: Operator 'contains' is not supported on this expression
Run Code Online (Sandbox Code Playgroud)

python mysql json sqlalchemy

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

列出目录中的所有文件 - 按大小过滤

我试图获取所有大于 20kb 的文件。
我尝试了以下但它返回所有文件,即使它们小于 20kb:

dir = 'C:\\some\\path'
filter(lambda x:os.path.getsize>20000L, [os.path.join(dir, x) for x in os.listdir(dir)])
Run Code Online (Sandbox Code Playgroud)

python python-2.7

2
推荐指数
1
解决办法
2858
查看次数