在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ attribute value must be a constant.

attribute value must be a constant.

package spittr.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import spittr.data.SpittleRepository;

import static org.springframework.web.bind.annotation.RequestMethod.GET;

@Controller
@RequestMapping ( "/spittles" )
public class SpittleController {

    private SpittleRepository spittleRepository;
    private static final String MAX_LONG_AS_STRING = Long.toString(Long.MAX_VALUE) + "";

    @Autowired
    public SpittleController(SpittleRepository spittleRepository) {
        this.spittleRepository = spittleRepository;
    }

    @RequestMapping ( method = GET )
    public String spittles(
            Model model,
            @RequestParam ( value = "max", defaultValue = SpittleController.MAX_LONG_AS_STRING) long max,
            @RequestParam ( value = "count", defaultValue = "20" ) int count) {
        model.addAttribute(
                "spittleList",
                spittleRepository.findSpittles(max, count)
        );
        return "spittles";
    }
}

@RequestParam 里的defaultvalue傳MAX_LONG_AS_STRING的時候提示錯誤attribute value must be a constant.可是我已經(jīng)在上面設置MAX_LONG_AS_STRING為靜態(tài)的了,為什么還會這樣提醒。相反,如果我把上方設置成

private static final String MAX_LONG_AS_STRING = "50";

就不會報錯.

求解這是為什么?如果涉及到編譯和運行期間的原理,希望大佬詳細解答。

回答
編輯回答
嘟尛嘴

恩,我找到了答案。。https://www.jianshu.com/p/f24...

2017年1月10日 13:35