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";
}
}
The default value in @ RequestParam prompts an error attribute value must be a constant. when passing Max _ LONG_AS_STRING But I have set MAX_LONG_AS_STRING to static above, why do you still remind me of this? On the contrary, if I set the top to
private static final String MAX_LONG_AS_STRING = "50";
there will be no error.
Why is this solved? If the principle during compilation and running is involved, I hope the boss will answer in detail.