---
# System prepended metadata

title: WOS - Part 1 Starter Template
tags: [Java, Template Notes]

---

###### tags: `Template Notes` `Java`

# WOS - Part 1 Starter Template
---
- Make sure to Command + Shift + o when editing the class and interface files to get the proper imports

## Step #1:
- See [Full Java Project Starter Notes](/qUu9Pfj-REiapIrri6tkjQ) on what to include for the files in this step
- Start a new spring app
    - edit pom file
    - create WEB-INF folder
        - Start adding the known jsp pages
    - edit application.properties
        - be sure to add db name
    - create db in workbench
    - in static folder create js and css folders
        - add .css and .js files to their folders

## Step #2:
- add 4 packages to the src/main/java > package that is there
    - controllers
    - models
    - repositories
    - services

## Step #3:
- Start working in Controllers package
    - Create 1st controller class
```java!=
@Controller
public class HomeController {
	@Autowired
	private <>Service <>Service;
	
	@GetMapping("/")
	public String index() {
		return "index.jsp";
	}
}

```
- Since <>Service is not created yet create that class inside the service package
```java!=
@Service
public class <>Service {
	@Autowired
	private <>Repository <>Repository;
}

```
- Since <>Repository isn't made yet create that interface in the repositories package
```java!=
@Repository
public interface <>Repository extends CrudRepository<<className>, Long> {

}

```
- Next we need to create our (className) model to import into the repository
```java!=
@Entity
@Table(name="className")
public class ClassName {
    @Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
    
    private String <columnName>;
    private String <columnName>;
    private String <columnName>;
    private String <columnName>;
    
    @Column(updatable = false)
	@DateTimeFormat(pattern = "yyy-MM-dd")
	private Date createdAt;
	@DateTimeFormat(pattern = "yyy-MM-dd")
	private Date updatedAt;
    
    //	Constructor
	public <ClassName>() {
		
	}
<!-- Here you will right click > Source > Generate Constructor Using Feilds > Uncheck id, createdAt and updatedAt     -->
<!-- It should fill in the constructor function     -->
    
<!-- Here you will right click again > Source > Generate Getters and Setters > Select all -->
<!-- They will be filled in here     -->
    @PrePersist
    protected void onCreate() {
        this.createdAt = new Date();
    }
    @PreUpdate
    protected void onUpdate() {
        this.updatedAt = new Date();
    }
}
```
## Step #4:
- Once the model file is done be sure to go back up the line in how each was created above and check the imports
- At this point all should be good to test the server
    - Right click the top folder of this app
    - Chose run as > Spring boot app
    - If all is good there should be no errors
    - open browser and go to localhost:8080