Skip to content

Commit b11c1a9

Browse files
committed
Added thymeleaf and freemarker support to tvguide springboot app
1 parent 94753d2 commit b11c1a9

13 files changed

Lines changed: 297 additions & 2 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.openapex.samples.misc.swing;
2+
3+
import javax.swing.*;
4+
import java.awt.*;
5+
import java.awt.event.ActionEvent;
6+
import java.awt.event.ActionListener;
7+
import java.io.File;
8+
import java.util.Arrays;
9+
10+
public class MultipleFileChooser extends JFrame {
11+
public static void main(String[] args) {
12+
MultipleFileChooser multipleFileChooser = new MultipleFileChooser();
13+
JFileChooser fileChooser = new JFileChooser();
14+
fileChooser.setMultiSelectionEnabled(true);
15+
JButton button = new JButton("Open Files");
16+
button.addActionListener(new ActionListener() {
17+
@Override
18+
public void actionPerformed(ActionEvent e) {
19+
int choice = fileChooser.showOpenDialog(multipleFileChooser);
20+
if (choice == JFileChooser.APPROVE_OPTION) {
21+
File[] openFiles = fileChooser.getSelectedFiles();
22+
System.out.println("Files: " + Arrays.toString(openFiles));
23+
}
24+
}
25+
});
26+
JPanel panel = new JPanel();
27+
panel.add(button);
28+
multipleFileChooser.add(panel);
29+
multipleFileChooser.setSize(new Dimension(400, 400));
30+
multipleFileChooser.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
31+
multipleFileChooser.setVisible(true);
32+
}
33+
}

java/springboot/pom.xml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.openapex.samples</groupId>
8+
<artifactId>springboot</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<parent>
12+
<groupId>org.openapex.samples</groupId>
13+
<artifactId>samples-main</artifactId>
14+
<version>0.0.1-SNAPSHOT</version>
15+
</parent>
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter-web</artifactId>
20+
<version>2.1.2.RELEASE</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-tomcat</artifactId>
25+
<version>2.1.2.RELEASE</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-data-jpa</artifactId>
30+
<version>2.1.2.RELEASE</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.postgresql</groupId>
34+
<artifactId>postgresql</artifactId>
35+
<version>42.2.5</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework.data</groupId>
39+
<artifactId>spring-data-mongodb</artifactId>
40+
<version>2.1.8.RELEASE</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.projectlombok</groupId>
44+
<artifactId>lombok</artifactId>
45+
<version>1.18.8</version>
46+
<scope>provided</scope>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.springframework.boot</groupId>
50+
<artifactId>spring-boot-devtools</artifactId>
51+
<version>2.1.2.RELEASE</version>
52+
<optional>true</optional>
53+
</dependency>
54+
</dependencies>
55+
56+
<build>
57+
<finalName>schoolserver</finalName>
58+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
59+
<plugins>
60+
<plugin>
61+
<artifactId>maven-clean-plugin</artifactId>
62+
<version>3.1.0</version>
63+
</plugin>
64+
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
65+
<plugin>
66+
<artifactId>maven-resources-plugin</artifactId>
67+
<version>3.0.2</version>
68+
</plugin>
69+
<plugin>
70+
<artifactId>maven-compiler-plugin</artifactId>
71+
<version>3.8.0</version>
72+
<configuration>
73+
<excludes>
74+
<exclude>node_modules/**</exclude>
75+
</excludes>
76+
</configuration>
77+
</plugin>
78+
<plugin>
79+
<artifactId>maven-surefire-plugin</artifactId>
80+
<version>2.22.1</version>
81+
</plugin>
82+
<plugin>
83+
<artifactId>maven-war-plugin</artifactId>
84+
<version>3.2.2</version>
85+
</plugin>
86+
<plugin>
87+
<artifactId>maven-install-plugin</artifactId>
88+
<version>2.5.2</version>
89+
</plugin>
90+
<plugin>
91+
<artifactId>maven-deploy-plugin</artifactId>
92+
<version>2.8.2</version>
93+
</plugin>
94+
<plugin>
95+
<groupId>org.springframework.boot</groupId>
96+
<artifactId>spring-boot-maven-plugin</artifactId>
97+
</plugin>
98+
</plugins>
99+
</pluginManagement>
100+
</build>
101+
</project>

java/tvguide/server/pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@
5050
<version>2.1.2.RELEASE</version>
5151
<optional>true</optional>
5252
</dependency>
53+
<!-- <dependency>-->
54+
<!-- <groupId>org.springframework.boot</groupId>-->
55+
<!-- <artifactId>spring-boot-starter-freemarker</artifactId>-->
56+
<!-- <version>2.1.2.RELEASE</version>-->
57+
<!-- </dependency>-->
58+
<dependency>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
61+
<version>2.1.2.RELEASE</version>
62+
</dependency>
5363
</dependencies>
5464

5565
<build>
@@ -63,7 +73,7 @@
6373
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
6474
<plugin>
6575
<artifactId>maven-resources-plugin</artifactId>
66-
<version>3.0.2</version>
76+
<version>3.0.2</version>
6777
</plugin>
6878
<plugin>
6979
<artifactId>maven-compiler-plugin</artifactId>

java/tvguide/server/src/main/java/org/openapex/tvguide/TvGuideApplication.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package org.openapex.tvguide;
22

33
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
45
import org.springframework.boot.autoconfigure.SpringBootApplication;
56
import org.springframework.boot.autoconfigure.domain.EntityScan;
67
import org.springframework.context.annotation.ComponentScan;
78
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
9+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
810

911
@SpringBootApplication
1012
@ComponentScan("org.openapex.tvguide")
1113
@EnableJpaRepositories("org.openapex.tvguide")
1214
@EntityScan("org.openapex.tvguide")
15+
//@EnableAutoConfiguration
16+
//@EnableWebMvc
1317
public class TvGuideApplication {
1418
public static void main(String[] args) {
1519
SpringApplication.run(TvGuideApplication.class, args);

java/tvguide/server/src/main/java/org/openapex/tvguide/controller/TvGuideController.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,49 @@
55
import org.openapex.tvguide.model.ProgramDocument;
66
import org.openapex.tvguide.service.TvGuideService;
77
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.stereotype.Controller;
9+
import org.springframework.ui.Model;
10+
import org.springframework.ui.ModelMap;
811
import org.springframework.web.bind.annotation.*;
12+
import org.springframework.web.servlet.ModelAndView;
913

1014
import java.util.List;
1115

12-
@RestController(value = "tvGuideController")
16+
@Controller(value = "tvGuideController")
17+
//@RestController(value = "tvGuideController")
1318
@RequestMapping(path = "/guide")
1419
@CrossOrigin(maxAge = 3600)
20+
1521
public class TvGuideController {
1622
@Autowired
1723
private TvGuideService tvGuideService;
1824

1925
@RequestMapping(method = RequestMethod.GET, path = "channels")
26+
@ResponseBody
2027
public List<Channel> getChannels() {
2128
return tvGuideService.getChannels();
2229
}
2330

2431
@RequestMapping(method = RequestMethod.GET, path = "search-channels")
32+
@ResponseBody
2533
public List<Channel> searchChannels(@RequestParam(name = "channelGroup", required = false) String group) {
2634
return tvGuideService.searchChannels(group);
2735
}
2836

2937
@RequestMapping(method = RequestMethod.POST, path = "channel")
38+
@ResponseBody
3039
public void createChannel(@RequestBody Channel channel) {
3140
tvGuideService.createChannel(channel);
3241
}
3342

3443
@RequestMapping(method = RequestMethod.GET, path = "programs")
44+
@ResponseBody
3545
public List<ProgramDocument> getPrograms() {
3646
return tvGuideService.getPrograms();
3747
}
3848

3949
@RequestMapping(method = RequestMethod.GET, path = "company")
50+
@ResponseBody
4051
public List<Company> getCompaniesQueryAnnotation() {
4152
return tvGuideService.getCompaniesQueryAnnotation();
4253
}
@@ -45,5 +56,25 @@ public List<Company> getCompaniesQueryAnnotation() {
4556
public List<Company> getCompaniesCustomQuery() {
4657
return tvGuideService.getCompaniesCustomQuery();
4758
}
59+
60+
@RequestMapping(path="/template")
61+
public ModelAndView getHelloTemplate(){
62+
ModelAndView model = new ModelAndView();
63+
model.setViewName("hello");
64+
model.addObject("message", "Hello World");
65+
return model;
66+
}
67+
68+
@RequestMapping(path="/template1")
69+
public String getHelloTemplate(Model model){
70+
model.addAttribute("message", "Hello World 1");
71+
return "hello";
72+
}
73+
74+
@RequestMapping(path="/template2")
75+
public String getHelloTemplate(ModelMap model){
76+
model.addAttribute("message", "Hello World 2");
77+
return "hello2";
78+
}
4879
}
4980

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Message</title>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
</head>
8+
<body>
9+
<p>
10+
Message: ${message}
11+
</p>
12+
</body>
13+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Message</title>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
</head>
8+
<body>
9+
<p>
10+
Message: [[${message}]]
11+
</p>
12+
</body>
13+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Message</title>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
</head>
8+
<body>
9+
<p>
10+
Message from a new API: ${message}
11+
</p>
12+
</body>
13+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Message</title>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
</head>
8+
<body>
9+
<p>
10+
Message from a new API: [[${message}]]
11+
</p>
12+
</body>
13+
</html>

web/html/57247715-OpenTwoUrls.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<html>
2+
3+
<head>
4+
</head>
5+
6+
<body>
7+
<a id="myLink" href="https://google.com" onclick="location.href='https://yahoo.com'" target="_blank">Click Here</a>
8+
<script>
9+
function makeDynamicUrlsAndChangeLink() {
10+
var link = document.getElementById("myLink");
11+
var param1 = "val1", param2 = "val2";
12+
var link1 = "https://google.com" + "?param1=" + param1 + "&param2=" + param2;
13+
var link2 = "location.href='https://vmware.com" + "?param1=" + param1 + "&param2=" + param2 + "'";
14+
link.setAttribute("href", link1);
15+
link.setAttribute("onclick", link2);
16+
}
17+
makeDynamicUrlsAndChangeLink();
18+
</script>
19+
</body>
20+
21+
</html>

0 commit comments

Comments
 (0)