43 lines
1.8 KiB
Plaintext
43 lines
1.8 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Spring Expression Language (SpEL) is an expression language used in the Spring Framework for evaluating and manipulating objects, properties, and conditions within Spring-based applications.
|
|
|
|
`org.springframework.ui.Model` is an interface in the Spring Framework that represents a container for data that can be passed between a controller and a view in a Spring MVC web application, allowing for data sharing during the request-response cycle.
|
|
|
|
Attributes added to the `org.springframework.ui.Model` should follow the Java identifier naming convention, which means they must start with a letter `a-z, A-Z`, underscore `_`, or a dollar sign `$` and may be followed by letters, digits, underscores, or dollar signs.
|
|
|
|
Failure to do so may result in SpEL parsing errors when using these attributes in template engines.
|
|
|
|
== How to fix it
|
|
|
|
Follow the Java identifier naming convention.
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,java,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
model.addAttribute(" a", 100); // Noncompliant (starts with a space)
|
|
model.addAttribute("a-b", 7); // Noncompliant (contains a hyphen)
|
|
model.addAttribute("1c", 42); // Noncompliant (starts with a digit)
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,java,diff-id=1,diff-type=compliant]
|
|
----
|
|
model.addAttribute("a", 100);
|
|
model.addAttribute("b", 42);
|
|
model.addAttribute("_c", 7);
|
|
model.addAttribute("$d", 8);
|
|
----
|
|
|
|
== Resources
|
|
|
|
=== Documentation
|
|
|
|
* https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html[Java SE - naming conventions]
|
|
* https://docs.spring.io/spring-framework/reference/core/expressions.html[Spring Expression Language (SpEL)]
|
|
* https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/ui/Model.html[Spring IO Docs - Interface Model]
|