简体   繁体   中英

Spring MVC - Creating Custom List Dynamically

I am trying to create a custom list from Spring MVC.

The main issue is I can't find any great sources on how to create a custom list... But here is the design I want and some code I have already.

Design 在此处输入图片说明

Code

JSP frontpage.jsp

<div id="result-panel">
            <ul>
            <c:forEach var="listValue" items="${offenderlists}">
                <li>OffenderId: <c:out value="${listValue.offenderId}"/> <li>
                </c:forEach>
            </ul>
        </div>

Java controller

@RequestMapping(value = "/", method = RequestMethod.POST)
    public String someMethod(@RequestParam("intelvalue") String valueOne) {
        ApplicationContext context = 
                new ClassPathXmlApplicationContext("Spring-Module.xml");
            OffenderDAO offenderDAO = (OffenderDAO) context.getBean("offenderDAO");
            Offender[] offenders = null;

            try {
                offenders = offenderDAO.requestOffenders(valueOne);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace(); 
            }
            for(Offender o: offenders) 
                System.out.println("offender: "+ o.OffenderId);
            ModelAndView model = new ModelAndView("frontpage");
            model.addObject("offenderlists", offenders);
            // Returned the list of offenders to jsp here...
            return "frontpage";
    }

I know I am doing it wrong I have in image url in the offender object along with everything I need I have no issues loading the offenders from my database. How do I create a list of offenders as show in design?

QUESTION How to create what is show in design with Spring MVC Models? Offender objects are loaded and data is within the objects I just need to display in list form how would I go at doing such?

References below were viewed and didn't provide a good enough example/answer. References: List<Foo> as form backing object using spring 3 mvc, correct syntax?

http://www.mkyong.com/spring-mvc/spring-mvc-and-list-example/

You may use a layout like in the fiddle below. http://jsfiddle.net/josangel555/oahkou2f/

Instead of the text's, you can use values like ${listValue.property} .

未显示的原因是因为我没有将ModelAndView返回为方法名somemethod的返回值

try

<div id="result-panel">
   <ul>
      <c:forEach var="listValue" items="${offenderlists}">
         <li>OffenderId: ${listValue.offenderId}<li>
      </c:forEach>
   </ul>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM