<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<url-pattern>
에는 사용할 url패턴 기입(여기서는 *.do)<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/context-root.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<param-value>
에 공통으로 사용할 의존성 설정파일 지정<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/context-web.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<url-pattern>
에는 사용할 url패턴 기입(여기서는 *.do)
@RequestMapping([value="]URL 패턴[", method={요청방식}, params="패러미터값"])
/sample?id=100일 경우 호출되는 어노테이션
@RequestMapping(value="/sample.do", method=GET, params="id=100")
Model addAttribute([키, ]값)
1. Controller
전후 생략
model.addAttribute("name","홍길동");
2. view
제 이름은 ${name }입니다.
3. 출력
제 이름은 홍길동입니다.
@Controller
public class HomeController {
@RequestMapping(path = "/home.do")
public String home() {
return "home.jsp";
}
}
@Controller
@RequestMapping("/emp")
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
// 요청핸들러 메서드
@RequestMapping(path = "/list.do")
public String list(Model model) {
// 전체 직원목록 조회
List<Employee> employees = employeeService.getAllEmployees();
// employee/list.jsp에 출력할 데이터를 Model에 저장한다.
model.addAttribute("employees", employees);
return "/employee/list.jsp";
}
}
<c:forEach var="emp" items="${employees }">
<tr>
<td>${emp.id }</td>
<td><a href="">${emp.firstName } ${emp.lastName }</a></td>
<td>${emp.phoneNumber }</td>
<td>${emp.jobId }</td>
<td><fmt:formatNumber value="${emp.salary }"/> 달러</td>
<td><fmt:formatDate value="${emp.hireDate }"/> </td>
</tr>
</c:forEach>