我有以下代码:
public class StudentController extends BaseController {
@RequestMapping(value = "/student/edit", method = RequestMethod.POST)
public String submitForm(@Valid @ModelAttribute(MODEL_ATTRIBUTE_STUDENT) StudentDTO edited,
BindingResult bindingResult, RedirectAttributes attributes) {
if (bindingResult.hasErrors()) {
return STUDENT_EDIT_FORM_VIEW;
}
//some logic...
}
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
dateFormat.setLenient(false);
// true passed to CustomDateEditor constructor means convert empty String to null
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
}
public class BaseController {
@ExceptionHandler(Exception.class)
protected ModelAndView handleAllException(Exception ex) {
Long errorId = System.currentTimeMillis() + RandomInteger.generate(1, Integer.MAX_VALUE); …Run Code Online (Sandbox Code Playgroud) 当我在选择字段中使用@Query注释时,我没有得到实体对象.我怎样才能获得实体对象?
public interface CreditCenterRepository extends JpaRepository<CreditCenter, Long> {
@Query("SELECT CC.id, CC.loanId, CC.clientId FROM CreditCenter CC")
List<CreditCenter> findAllIds();
}
Run Code Online (Sandbox Code Playgroud)
当我从我的控制器调用此方法时,它不会抛出任何错误,但是,当我尝试迭代它时抛出classcastexception
List<CreditCenter> objects = findAllIds();
for (CreditCenter cc : objects) { //This line throws ClassCastException
//some logic
}
Run Code Online (Sandbox Code Playgroud) 我在模式中定义了以下字段。当我使用 avro 插件生成 java 对象时,我得到定义为“java.util.List”的同义词。在某些情况下我是否可以强制插件生成“java.util.Set”?
{
"name" : "synonyms",
"type" : {
"type" : "array",
"items" : "string",
"java-class" : "java.util.Set"
}
Run Code Online (Sandbox Code Playgroud)
这是生成的类的相关部分。不知道为什么会生成 @deprecated 注释..!
@Deprecated public java.util.List<java.lang.CharSequence> synonyms;
Run Code Online (Sandbox Code Playgroud)
撞..