BAEL-1275 Introduction to ActiveWeb (#3638)
* BAEL-1275 Introduction to active web first commit * BAEL-1275 Added the module to parent pom * BAEL-1275 Introduction to ActiveWeb
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
2399b4d817
commit
d7aecc83de
@@ -3,7 +3,15 @@ package app.config;
|
||||
import org.javalite.activeweb.AppContext;
|
||||
import org.javalite.activeweb.Bootstrap;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import app.services.ArticleServiceModule;
|
||||
|
||||
public class AppBootstrap extends Bootstrap {
|
||||
public void init(AppContext context) {
|
||||
}
|
||||
public Injector getInjector() {
|
||||
return Guice.createInjector(new ArticleServiceModule());
|
||||
}
|
||||
}
|
||||
|
||||
28
java-lite/src/main/java/app/controllers/ArticleController.java
Executable file
28
java-lite/src/main/java/app/controllers/ArticleController.java
Executable file
@@ -0,0 +1,28 @@
|
||||
package app.controllers;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.javalite.activeweb.AppController;
|
||||
|
||||
import app.services.ArticleService;
|
||||
|
||||
public class ArticleController extends AppController {
|
||||
|
||||
@Inject
|
||||
private ArticleService articleService;
|
||||
|
||||
public void index() {
|
||||
view("articles", articleService.getArticles());
|
||||
}
|
||||
|
||||
public void search() {
|
||||
|
||||
String keyword = param("key");
|
||||
if (null != keyword) {
|
||||
assign("article", articleService.search(keyword));
|
||||
} else {
|
||||
render("/common/error");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
11
java-lite/src/main/java/app/controllers/HomeController.java
Executable file
11
java-lite/src/main/java/app/controllers/HomeController.java
Executable file
@@ -0,0 +1,11 @@
|
||||
package app.controllers;
|
||||
|
||||
import org.javalite.activeweb.AppController;
|
||||
|
||||
public class HomeController extends AppController {
|
||||
|
||||
public void index() {
|
||||
render("index");
|
||||
}
|
||||
|
||||
}
|
||||
50
java-lite/src/main/java/app/models/Article.java
Executable file
50
java-lite/src/main/java/app/models/Article.java
Executable file
@@ -0,0 +1,50 @@
|
||||
package app.models;
|
||||
|
||||
public class Article {
|
||||
|
||||
private String title;
|
||||
private String author;
|
||||
private String words;
|
||||
private String date;
|
||||
|
||||
public Article(String title, String author, String words, String date) {
|
||||
super();
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
this.words = words;
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public String getWords() {
|
||||
return words;
|
||||
}
|
||||
|
||||
public void setWords(String words) {
|
||||
this.words = words;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(String date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
}
|
||||
13
java-lite/src/main/java/app/services/ArticleService.java
Executable file
13
java-lite/src/main/java/app/services/ArticleService.java
Executable file
@@ -0,0 +1,13 @@
|
||||
package app.services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import app.models.Article;
|
||||
|
||||
public interface ArticleService {
|
||||
|
||||
List<Article> getArticles();
|
||||
|
||||
Article search(String keyword);
|
||||
|
||||
}
|
||||
34
java-lite/src/main/java/app/services/ArticleServiceImpl.java
Executable file
34
java-lite/src/main/java/app/services/ArticleServiceImpl.java
Executable file
@@ -0,0 +1,34 @@
|
||||
package app.services;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import app.models.Article;
|
||||
|
||||
public class ArticleServiceImpl implements ArticleService {
|
||||
|
||||
public List<Article> getArticles() {
|
||||
return fetchArticles();
|
||||
}
|
||||
|
||||
public Article search(String keyword) {
|
||||
Article ar = new Article("Article with " + keyword, "baeldung", "1250", Instant.now()
|
||||
.toString());
|
||||
return ar;
|
||||
}
|
||||
|
||||
private List<Article> fetchArticles() {
|
||||
Article ar1 = new Article("Introduction to ActiveWeb", "baeldung", "1650", Instant.now()
|
||||
.toString());
|
||||
|
||||
Article ar = new Article("Introduction to Mule", "baeldung", "1650", Instant.now()
|
||||
.toString());
|
||||
List<Article> articles = new ArrayList<Article>();
|
||||
articles.add(ar);
|
||||
articles.add(ar1);
|
||||
return articles;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
12
java-lite/src/main/java/app/services/ArticleServiceModule.java
Executable file
12
java-lite/src/main/java/app/services/ArticleServiceModule.java
Executable file
@@ -0,0 +1,12 @@
|
||||
package app.services;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
public class ArticleServiceModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(ArticleService.class).to(ArticleServiceImpl.class)
|
||||
.asEagerSingleton();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user