Use Java's OSS framework Nablarch to check communication + α. Nablarch is a framework that can be used for various purposes such as web applications, web services, batch messaging. This time we will create a web application project. (It is undecided whether to create an article on other execution control infrastructure.)
OS: OS X Yosemite 10.10.5 Maven: Apache Maven 3.3.3 IDE: IntelliJ IDEA 2016.2.3 Nablarch: 5u8
Create a blank project and just touch it. Acquires and displays the information registered in the DB.
Create it by referring to How to create a blank project. For the time being, it seems that you can hit the following command to create it, so hit it. The version has been changed to 5u8.
mvn archetype:generate -DarchetypeGroupId=com.nablarch.archetype -DarchetypeArtifactId=nablarch-web-archetype -DarchetypeVersion=5u8
Then, you will be asked for the project information, so enter it. This time, enter the same one as described in the procedure.
With that, you have a blank project! Let's open it in the IDE right away!
You can do it! Next, let's check the communication. If you execute clean, compile, waitt: run with the maven command, the web application will start and be displayed in the browser.
It's working fine! Then, I will customize it a little. It's a lot of work because you just touch it and check the operation. .. ..
First, prepare a DB table for data acquisition. Create a PERSON table with ID / NAME / AGE columns and insert one data. This time, I ran it with IntelliJ's database access function. Connection information can be found in src / env / dev / resources / env.config.
Next, prepare Entity class to hold what is obtained from DB.
Person.java
@Entity
public class Person {
@Id
private String id;
private String name;
private Integer age;
// getter,setter omitted
}
Next, create an action class (logic part). Get the data from the PERSON table, set it in request scope and pass it to jsp.
PersonAction.java
public class PersonAction {
public HttpResponse search(HttpRequest request, ExecutionContext context) {
List<Person> data = UniversalDao.findAll(Person.class);
context.setRequestScopedVar("data", data);
return new HttpResponse("/person/list.jsp");
}
}
Finally, create jsp.
list.jsp
<!--html Standard part omitted-->
<table border="1">
<tr>
<th>name</th>
<th>age</th>
</tr>
<c:forEach items="${data}" var="d">
<tr>
<td><n:write name="d.name" /></td>
<td><n:write name="d.age" /></td>
</tr>
</c:forEach>
</table>
That's all there is to it.
mvn clean compile waitt:run
Go to http: // localhost: 9080 / action / person / search in your browser.
It is displayed!
By the way, this URL can be mapped to src / main / resources / routes.xml
<match path="/action/:controller/:action"/>
Since there is, it is mapped to the search method of the PersonAction class.
For details, I left it to Nablarch's Explanation and omitted the explanation, but as mentioned above I was able to create a web application quickly. When it comes to actual development, it works (blank project and [Example] as an implementation example (https://github.com/nablarch/nablarch-example-web)) even if it is not crisp because there are many contents to customize. I felt that it was easy to touch that) could be prepared immediately. I really wish I could compare it with other frameworks, but I gave it up because of my shallow learning. The one created this time is posted on github.
Recommended Posts