spring-el

Thymeleaf + Spring : How to keep line break?

杀马特。学长 韩版系。学妹 提交于 2019-11-30 08:22:35
I'm using Thymeleaf template engine with spring and I'd like to display text stored throught a multiline textarea. In my database multiline string are store with "\n" like this : "Test1\nTest2\n...." With th:text i've got : "Test1 Test2" with no line break. How I can display line break using Thymeleaf and avoid manually "\n" replacing with < br/> and then avoid using th:utext (this open form to xss injection) ? Thanks ! Two of your options: Use th:utext - easy setup option, but harder to read and remember Create a custom processor and dialect - more involved setup, but easier, more readable

Thymeleaf: show text if the attribute and property exists

前提是你 提交于 2019-11-30 07:52:02
问题 Is there a simple way in thymeleaf to show the content of an attribute property if the property and the attribute exist? If there's an attribute "error" with a property "summary" in my html page, I'd like to show it: <span th:text="${error.summary}">error summary</span> If there is no attribute "error" the following error is raised: org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'summary' cannot be found on null Currently I'm using the

spring expression read file content

余生颓废 提交于 2019-11-30 07:26:46
How to use spring expression to read file content and put it into a string? I would like to do the following. For example, @Value("classpath:myquery.sql") File f; @Value("#{org.apache.commons.io.FileUtils.readFileToString(f)}") String sql; Or even better @Value("#{FileUtils.readFileToString(classpath:myquery.sql)}") String sql; However, none of above code work. Just to mention I am using spring version 3.2.0 Thanks. Finally got the answer myself... @Value("#{T(org.apache.commons.io.FileUtils).readFileToString(" + "T(org.springframework.util.ResourceUtils).getFile('classpath:myquery.sql')" + ")

How to inject a bean only when it exists

穿精又带淫゛_ 提交于 2019-11-30 04:55:05
问题 I have the following structure of spring context files ( -> stands for 'includes') : A1.xml -> B.xml & C.xml A2.xml -> B.xml C.xml defines a bean c B.xml defines a bean b with a dependency on c Obviously this fails for A2, because there is no c defined in the context A2 . How can I specify something like: if you have c in the context inject it in b otherwise just inject null ? I looked into Spring EL but <property name="b" ref="#{ @c?:null}" /> Just gave me a NoSuchBeanDefinitionException for

What are the Spring Batch “default” Context Variables?

南笙酒味 提交于 2019-11-30 04:05:06
问题 In the Spring Batch step-scope documentation, there are three unexplained spring-batch context maps: jobParameters , jobExecutionContext , and stepExecutionContext . Springsource sample code, combined: <bean id="flatFileItemReader" scope="step" class="org.springframework.batch.item.file.FlatFileItemReader"> <property name="var1" value="#{jobParameters['input.file.name']}" /> <property name="var2" value="#{jobExecutionContext['input.file.name']}" /> <property name="var3" value="#

Spring Expression Language in custom annotation

被刻印的时光 ゝ 提交于 2019-11-30 03:25:36
问题 I want to use Spring Expression Language in a custom Annotation. This annotation will be consumed by a custom Aspect. Check this out: @StatisticEventTrigger(value = TestStatisticEvent.class, expression = "#p1") public void someOtherMethod(String arg1, Long arg2) { As you can see, i want to use the expression (in this case) to retrieve some specific argument. When I have my Aspect, triggering an annotated method, i would like to evaluate the spring expression (programmatically) to retrieve a

Spring - SpEL evaluates entity argument as null reference in @PreAuthorize(“hasPermission”)

我与影子孤独终老i 提交于 2019-11-29 12:14:43
I've got problem that SpEL is evaluating entity argument as null reference in the second method of this repository. This first method works well and id is correctly evaluated to Long as should be. @NoRepositoryBean public interface SecuredPagingAndSortingRepository<T extends AuditedEntity, ID extends Serializable> extends PagingAndSortingRepository<T, ID> { @Override @RestResource(exported = false) @PreAuthorize("hasPermission(#id, null, 'owner')") void delete(ID id); @Override @PreAuthorize("hasPermission(#entity, 'owner')") void delete(T entity); } This is my custom PermissionEvaluator:

Can Spring evaluate all characters/expressions in SpEL expressions as they are injected from a property file?

我怕爱的太早我们不能终老 提交于 2019-11-29 11:51:28
I wonder why spring doesn't directly evaluate all expressions as they are injected from a property file into @PreAuthorize(...) annotation. I think spring doesn't evaluate some characters like '(', ')', ''', etc or it adds special characters on top of those injected values from property file. To clarify, let us consider the following example. @PreAuthorize("hasRole('ROLE_ADMIN')") The above expression is normal, and works fine. Suppose values of the property file are the following. role1=ROLE_ADMIN role2='ROLE_ADMIN' role3=hasRole('ROLE_ADMIN') Let us inject role1 from property file and pass

Thymeleaf + Spring : How to keep line break?

偶尔善良 提交于 2019-11-29 11:05:16
问题 I'm using Thymeleaf template engine with spring and I'd like to display text stored throught a multiline textarea. In my database multiline string are store with "\n" like this : "Test1\nTest2\n...." With th:text i've got : "Test1 Test2" with no line break. How I can display line break using Thymeleaf and avoid manually "\n" replacing with < br/> and then avoid using th:utext (this open form to xss injection) ? Thanks ! 回答1: Two of your options: Use th:utext - easy setup option, but harder to

Thymeleaf: show text if the attribute and property exists

喜欢而已 提交于 2019-11-29 05:31:29
Is there a simple way in thymeleaf to show the content of an attribute property if the property and the attribute exist? If there's an attribute "error" with a property "summary" in my html page, I'd like to show it: <span th:text="${error.summary}">error summary</span> If there is no attribute "error" the following error is raised: org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'summary' cannot be found on null Currently I'm using the following approach, which just seems too complicated. <span th:if="${error != null and error.summary != null}">