作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个像这样的 MVC 逻辑。
汽车绑定(bind)模型
package com.rentautosofia.rentacar.bindingModel
import javax.validation.constraints.Size
class CarBindingModel(@Size(min = 1)
var name: String = "",
@Size(min = 1)
var price: Int = 0,
@Size(min = 1)
var imgURL: String = "",
var isLPG: Boolean? = false)
package com.rentautosofia.rentacar.controller.admin
import ...
const val PATH_ADMIN_CAR = "admin/car"
const val PATH_ADMIN_ALL_CARS = "$PATH_ADMIN_CAR/all"
@RequestMapping("/$PATH_ADMIN_CAR")
@Controller
class CarController @Autowired
constructor(private val carRepository: CarRepository) {
@GetMapping("/create")
fun create(model: Model): String {
model.addAttribute("car", CarBindingModel())
model.addAttribute("view", "$PATH_ADMIN_CAR/create")
return "base-layout"
}
@PostMapping("/create")
fun createProcess(model: Model, @Valid carBindingModel:
CarBindingModel, bindingResult: BindingResult): String {
if (bindingResult.hasErrors()) {
model.addAttribute("view", "$PATH_ADMIN_CAR/create")
model.addAttribute("message", "Invalid data.")
model.addAttribute("car", carBindingModel)
return "base-layout"
}
val car = car {
name = carBindingModel.name
price = carBindingModel.price
imgURL = carBindingModel.imgURL
isLPG = carBindingModel.isLPG
}
this.carRepository.saveAndFlush(car)
return "redirect:/$PATH_ADMIN_ALL_CARS"
}
...
}
<input id="isLPG" type="checkbox" name="isLPG" th:checked="${car.isLPG}"/>
isLPG
在
CarBindingModel
.
An error happened during template parsing (template: "class path resource [templates/base-layout.html]")
Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "car.isLPG" (template: "admin/car/create" - line 16, col 65)
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "car.isLPG" (template: "admin/car/create" - line 16, col 65)
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:
Property or field 'isLPG' cannot be found on object of type 'com.rentautosofia.rentacar.bindingModel.CarBindingModel' - maybe not public?
org.springframework.expression.spel.SpelEvaluationException: EL1008E:
Property or field 'isLPG' cannot be found on object of type 'com.rentautosofia.rentacar.bindingModel.CarBindingModel' - maybe not public?
最佳答案
看起来 SpEL 被 is
混淆了字首。
这有效
package foo
class CarBindingModel(
var name: String = "",
var price: Int = 0,
var imgURL: String = "",
var LPG: Boolean? = false)
public class So49863132Application {
public static void main(String[] args) {
CarBindingModel car = new CarBindingModel("Lexus", 42, "img.png", true);
Expression exp = new SpelExpressionParser().parseExpression("name + ' ' + price + ' ' + LPG");
System.out.println(exp.getValue(car));
}
}
Lexus 42 true
isLPG
, kotlin 生成
isLPG()
.
isIsLPG()
.
关于spring-boot - 在 'isLPG' 类型的对象上找不到属性或字段 'com.rentautosofia.rentacar.bindingModel.CarBindingModel' - 也许不是公共(public)的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49863132/
我有一个像这样的 MVC 逻辑。 汽车绑定(bind)模型 package com.rentautosofia.rentacar.bindingModel import javax.validatio
我是一名优秀的程序员,十分优秀!