title: Displaying a view (list of all employees) from a Controller in Spring MVC
body: <p>Trying to simply output a list of all employees in a view report from a controller in Spring. Getting an error relating to Freemarker, unsure of how to resolve.</p>
  
  <p>Relevant classes:</p>
  
  <p><strong>Employee.java model</strong></p>
  
  <pre><code>package mvc_course.models;
  
  import java.util.HashSet;
  import java.util.Set;
  
  public class Employee {
  
  int employee_number;
  String employee_name;
  String address;
  String ni_number;
  String iban_number;
  double starting_salary;
  int employee_type_id;
  int commission_rate;
  int total_sales;
  
  public static Set&lt;Employee&gt; employeeList = new HashSet&lt;Employee&gt;();
  
  public Employee(String name, String address, String nin, String iban, double salary) {
      this.employee_name = name;
      this.address = address;
      this.ni_number = nin;
      this.iban_number = iban;
      this.starting_salary = salary;
  }
  
  public int getEmployee_number() {
      return employee_number;
  }
  
  public void setEmployee_number(int employee_number) {
      this.employee_number = employee_number;
  }
  
  public String getEmployee_name() {
      return employee_name;
  }
  
  public void setEmployee_name(String employee_name) {
      this.employee_name = employee_name;
  }
  
  public String getAddress() {
      return address;
  }
  
  public void setAddress(String address) {
      this.address = address;
  }
  
  public String getNi_number() {
      return ni_number;
  }
  
  public void setNi_number(String ni_number) {
      this.ni_number = ni_number;
  }
  
  public String getIban_number() {
      return iban_number;
  }
  
  public void setIban_number(String iban_number) {
      this.iban_number = iban_number;
  }
  
  public double getStarting_salary() {
      return starting_salary;
  }
  
  public void setStarting_salary(double starting_salary) {
      this.starting_salary = starting_salary;
  }
  
  public int getEmployee_type_id() {
      return employee_type_id;
  }
  
  public void setEmployee_type_id(int employee_type_id) {
      this.employee_type_id = employee_type_id;
  }
  
  public int getCommission_rate() {
      return commission_rate;
  }
  
  public void setCommission_rate(int commission_rate) {
      this.commission_rate = commission_rate;
  }
  
  public int getTotal_sales() {
      return total_sales;
  }
  
  public void setTotal_sales(int total_sales) {
      this.total_sales = total_sales;
  }
  
  }
  </code></pre>
  
  <p><strong>ReportController.java</strong></p>
  
  <pre><code>    package mvc_course.controllers;
  
  import java.sql.Connection;
  import java.sql.ResultSet;
  import java.sql.Statement;
  import java.util.ArrayList;
  import java.util.List;
  
  import javax.sql.DataSource;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.RequestMapping;
  
  import mvc_course.models.Employee;
  
  @Controller
  public class ReportController {
  
      @Autowired
      private DataSource dataSource;
  
      @RequestMapping(value="showEmployees.mvc")
      public String showEmployees(Model m){
  
          List&lt;Employee&gt; employees = new ArrayList&lt;Employee&gt;();
  
          try{
              Connection c = dataSource.getConnection();
              Statement s = c.createStatement();
              String sql = "SELECT * FROM Employees";
              ResultSet rs = s.executeQuery(sql);
  
              List&lt;String[]&gt;rows = new ArrayList&lt;String[]&gt;();
  
              while(rs.next()){
  
              String[] row = {
                          rs.getString(1),
                          rs.getString(2),
                          rs.getString(3),
                          rs.getString(4),
                          rs.getString(5),
                          rs.getString(6)};
                  rows.add(row);
                  }
  
              for (String[] row : rows) {
                  Employee e = new Employee(row[1], row[2], row[3], row[4], Double.parseDouble(row[5]));
                  employees.add(e);
                  System.out.println();
                  for (String string : row) {
                      System.out.print(string + " ");
                  }
              }
  
              m.addAttribute("employees");
  
  
          }catch (Exception e){
              System.out.println(e.getMessage());
          }
  
  
          return "EmployeesPerBuReport";
  
      }
  
  }
  
  
  **EmployeeReport.ftl**
  
      &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;title&gt;Employees per BU&lt;/title&gt;
  
  &lt;!-- Compiled and minified CSS --&gt;
    &lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/css/materialize.min.css"&gt;
  
    &lt;!-- Compiled and minified JavaScript --&gt;
    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/js/materialize.min.js"&gt;&lt;/script&gt;
  
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;h1&gt;Employees&lt;/h1&gt;
  &lt;table&gt;
  &lt;thead&gt;
  &lt;tr&gt;
      &lt;th&gt;Name&lt;/th&gt;
      &lt;th&gt;Address&lt;/th&gt;
      &lt;th&gt;National Insurance Number&lt;/th&gt;
      &lt;th&gt;Bank Account Number&lt;/th&gt;
      &lt;th&gt;Starting Salary&lt;/th&gt;
  &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
  &lt;#list employees as employee&gt;
              &lt;tr&gt;
                  &lt;td&gt;${employee.getName}&lt;/td&gt;
                  &lt;td&gt;${employee.getAddress}&lt;/td&gt;
                  &lt;td&gt;${employee.getNi_number}&lt;/td&gt;
                  &lt;td&gt;${employee.getIban_number}&lt;/td&gt;
                  &lt;td&gt;${employee.getStarting_salary}&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/#list&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
    <p>FreeMarker template error (DEBUG mode; use RETHROW in production!):
    The following has evaluated to null or missing: ==> employee.getName
    [in template "EmployeesPerBuReport.ftl" at line 31, column 39] ----
    Tip: It's the step after the last dot that caused this error, not
    those before it. ---- Tip: If the failing expression is known to be
    legally refer to something that's sometimes null or missing, either
    specify a default value like myOptionalVar!myDefault, or use &lt;#if
    myOptionalVar??>when-present&lt;#else>when-missing. (These only cover the
    last step of the expression; to cover the whole expression, use
    parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ----
    ---- FTL stack trace ("~" means nesting-related): - Failed at: ${employee.getName} [in template "EmployeesPerBuReport.ftl" at line
    31, column 37</p>
  </blockquote>