Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ViewPersonController extends org.springframework.web.servlet.mvc.AbstractController
- {
- private static final Format MY_DATE_FORMAT = new SimpleDateFormat(...);
- protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
- {
- Person person = get person from backing service layer or database
- Map properties = new HashMap();
- // No formatting required, name is a String
- properties.put("name", person.getName());
- // getBirthDate() returns Date and is formatted by a Format
- properties.put("birthDate", MY_DATE_FORMAT.format(person.getBirthDate()));
- // latitude and longitude are separate fields in Person, but in the UI it's one field
- properties.put("location", person.getLatitude() + ", " + person.getLongitude());
- return new ModelAndView("viewPerson", "person", properties);
- }
- }
- Name = <c:out value="${person. name}" /><br>
- Birth Date = <c:out value="${person. birthDate}" /><br>
- Location = <c:out value="${person. location}" /><br>
- <%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
- <fmt:formatDate type="date" value="${person. birthDate}" />
- public class Person {
- public String getLocation() {
- return this.latitude.concat(", ").concat(this.longitude);
- }
- }
Add Comment
Please, Sign In to add comment