spring-mvc

Thymeleaf classappend for multiple classes

▼魔方 西西 提交于 2020-01-30 04:31:17
问题 I want to add multiple classes using condition. <div th:classappend="x.isTrue ?'class1' " ></div> I want something like <div th:classappend="x.isTrue ?'class1' and "y.isTrue ?'class2'" ></div> 回答1: You can use literal substitutions to achieve this: <div th:classappend="|${x.isTrue ? 'class1' : ''} ${y.isTrue ? 'class2' : ''}|"></div> Another method is to simply wrap your conditions with brackets and concatenate them: <div th:classappend="${(x.isTrue ? 'class1' : '') + (y.isTrue ? ' class2' :

How to insert a linebreak as the data of a cell?

为君一笑 提交于 2020-01-29 15:48:09
问题 I use Apache POI 3.16 to create an Excel file. I want to set the data inside a particular cell to have a linebreak : rowConsommationEtRealisation.createCell(0).setCellValue("Consommation (crédits)\r\nRéalisation (produits)"); When I open the file then the cell value does not have linebreak ! So how to create linebreak ? 回答1: Try this: here Row row = sheet.createRow(2); Cell cell = row.createCell(2); cell.setCellValue("Use \n with word wrap on to create a new line"); //to enable newlines you

Spring 4 WebSocket Remote Broker configuration

六眼飞鱼酱① 提交于 2020-01-28 20:59:30
问题 I managed to create simple Websocket application with Spring 4 and Stomp. See my last question here Then I tried to use remote message broker(ActiveMQ). I just started the broker and changed registry.enableSimpleBroker("/topic"); to registry.enableStompBrokerRelay("/topic"); and it worked. The question is how the broker is configured? I understand that in this case the application automagicaly finds the broker on localhost:defaultport, bu what if I need to point the app to some other broker

Spring 4 WebSocket Remote Broker configuration

两盒软妹~` 提交于 2020-01-28 20:55:40
问题 I managed to create simple Websocket application with Spring 4 and Stomp. See my last question here Then I tried to use remote message broker(ActiveMQ). I just started the broker and changed registry.enableSimpleBroker("/topic"); to registry.enableStompBrokerRelay("/topic"); and it worked. The question is how the broker is configured? I understand that in this case the application automagicaly finds the broker on localhost:defaultport, bu what if I need to point the app to some other broker

UTF-8 encoding in Spring MVC, problem with FORMs

做~自己de王妃 提交于 2020-01-27 03:21:05
问题 I have this in web.xml <filter> <filter-name>encoding-filter</filter-name> <filter-class> org.springframework.web.filter.CharacterEncodingFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encoding-filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> and at the top of file.jsp

What data is locked by @Transactional annotation?

匆匆过客 提交于 2020-01-26 04:00:29
问题 I need to implement an MVC web service. I selected Spring MVC/Data JPA for this purpose So my service need to: Load some entities Make some business logic on it Update the entities and store it All above need to be in atomic manner Some code snippet to clarify: @Service public class AService { @Autowired private Repository1 repository1; @Autowired private Repository2 repository2; @Autowired private Repository3 repository3; @Transactional public Result getResult(Long id) { Entity1 e1 =

Convert object containing repeated fields to JSON

孤街醉人 提交于 2020-01-26 02:28:25
问题 I have two table country and city in mysql dababase and i make a query to return records like that as List<myDTO> : 1,france,1,paris 1,france,2,marseille 1,france,3,lion .... MyDTO public class MyDTO { public Integer idLvl1; public String nameLvl1; public Integer idLvl2; public String nameLvl2; public MyDTO(Integer idLvl1, String nameLvl1, Integer idLvl2, String nameLvl2) { this.idNiv1 = idLvl1; this.nomNiv1 = nameLvl1; this.idNiv2 = idLvl2; this.nomNiv2 = nameLvl2; } How can i convert it to

Chaining setParameter on Hibernate Query

孤者浪人 提交于 2020-01-25 23:47:05
问题 As you can see I have two named parameters, one being set by setParameterList() and one being set by setParmeter(). The problem is the List is not being ordered. When I set the order field explicitly it works fine, but the same string is being passed into the method it doesn't work. Is it that setParameter and and setParameterList can't be chained? They both return a query do I don't see why not. What am I missing? public List<Subject> getSubjectsByMedium(String orda, Medium... medium) { List

How to call @PreDestroy for a bean declared with @Bean annotation

谁说胖子不能爱 提交于 2020-01-25 23:04:39
问题 I have a bean declared with annotation @Bean @Bean public Set<DefaultMessageListenerContainer> beans() { Set<DefaultMessageListenerContainer> containerSet = new HashSet<DefaultMessageListenerContainer>(); return containerSet; } I have some operations to be performed when I am destroying the bean. How can I achieve that? I know I can use @predestroy annotation on a method in a class annotated with @Component but not sure how can I do that when declared @Bean annotation. EDIT : @Bean

Writing to a new file with erasing previous data Java

馋奶兔 提交于 2020-01-25 21:09:05
问题 I am working on a project, and having file object set through spring (beans), and using RequiredArgsConstructor of Lombok to do so. Code: Spring.xml: <bean id=".." class="ImageDataProcess"> <constructor-arg ref="x.y.z.file.newImageDataFile" /> <other constructor args> </bean> ImageDataProcess.java: @RequiredArgsConstructor public class ImageDataProcess implements PQR { private final File newImageDataTextFile; //other values coming from spring @Override public void execute() { ://logic here :