小编Abh*_*oor的帖子

404的Spring启动自定义错误页面

我希望有自定义404错误页面.我在类路径中有速度,但我不想使用速度视图解析器下面是我的代码

@EnableAutoConfiguration(exclude={VelocityAutoConfiguration.class})
@ComponentScan
public class Application {
Properties props = new Properties();

public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)

我无法将所有404重定向到资源目录中的某些html.

请协助

PS如果我使用velocityresolver并且在模板目录中有error.vm,它可以工作.

谢谢你的问候

spring-boot

5
推荐指数
2
解决办法
9848
查看次数

在java中输入推断

你能解释一下为什么下面的工作方式确实如此.在我看来,java类型系统很难推断出R的类型

public class Test {

interface Parser<A,R>{
    R parse(A a);
}

static class ResponseParser implements Parser<String,Integer>{

    public Integer parse(String s) {
        return Integer.parseInt(s) + 1;
    }
}

interface Function<A,R>{
    R with(A a);
}

public static <A,R,P extends Parser<A,R>> Function<P,R> getResult(final A res){
        return new Function<P, R>() {
            public R with(P parser) {
                return parser.parse(res);
            }
        };
}

public static void main(String [] args){
    Function<Parser<String,Integer>, Integer> func = getResult("1");
    //this works
    func.with(new ResponseParser());
    // why this does not work
    getResult("1").with(new ResponseParser()); …
Run Code Online (Sandbox Code Playgroud)

java generics types

5
推荐指数
1
解决办法
179
查看次数

将递归函数分配给scala中的变量

下面的代码给出了这一行多个标记的错误 - 递归值factWithTailRec需要类型 - 找到隐式转换:i => int2bigIn

@tailrec
 val factWithTailRec = (i:Int, acc:BigInt) =>   if(i == 0) 1  else factWithTailRec(i-1, i * acc)
Run Code Online (Sandbox Code Playgroud)


可以请建议我如何防止它.要求是将val分配给递归函数

scala

0
推荐指数
1
解决办法
211
查看次数

在scala中按名称调用

两个问候方法都一样

object test {
  def greet = { println("hi")}                    //> greet: => Unit
  def greet1(f: => Unit)= {println("hi")}         //> greet1: (f: => Unit)Unit
}
Run Code Online (Sandbox Code Playgroud)

根据我的理解greet是一个函数,它不接受任何参数并返回Unit和参数按名称调用.而greet1是需要函数返回单位,也可以通过名字为它的参数调用的函数.很困惑,任何人都可以善解释这种差异.

scala

0
推荐指数
1
解决办法
113
查看次数

标签 统计

scala ×2

generics ×1

java ×1

spring-boot ×1

types ×1