Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

View & Controller

Su Su Lin
Day2

1
Step 1 How to connect Controller and View?
Build new package / Class

Source Folder
- src/main/resources

Package
- templates/account
- templates/home

Source Folder
- src/main/java

Package
- gic/controller/AccountController

Package
- gic/dto

2
Step 2 Account Controller Step 3 Account View
File -> New -> Class File -> New -> Other -> Web -> HTML File

3
Step 4 Write Mapping Between Controller and View

AccountController.java account.html

4
Step 5 Build Main Class for Project Run
File -> New -> Class

5
Step 6 Run Main Class and Call localhost from browser
Appliation.java -> Right Click -> Run As -> Gradle Test or Java Application

6
If the tomcat connector configured to listen on port 8080 failed to start, change port.
General -> File Save As .yml

7
Step 7 Create account_list.html and Connect with Account Controller
File -> New -> Other -> Web -> HTML File

8
Step 8 @RequestMapping declare in class level
AccountController declare @RequestMapping("/") and init method must have write method = RequestMethod.GET

9
Step 9 Variable Passing from Controller to View
th:text="${msg}" model.addAttribute("msg", "User Input is invalid.");

th:utext="${msg}" model.addAttribute("msg", "<p style='color:red'>User Input is invalid.</p>");

10
①https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html

②http://www.mybatis.org/mybatis-3/sqlmap-xml.html

③https://www.tutorialspoint.com/mybatis/mybatis_annotations.htm

④http://parsleyjs.github.io/Parsley-1.x/documentation.html

11

You might also like