SpringMVC 注解2

来源:互联网 发布:淘宝监管记录怎么消除 编辑:程序博客网 时间:2024/05/17 22:56
<?xml version="1.0" encoding="UTF-8"?><beans  xmlns="http://www.springframework.org/schema/beans"        xmlns:aop="http://www.springframework.org/schema/aop"        xmlns:tx="http://www.springframework.org/schema/tx"        xmlns:context="http://www.springframework.org/schema/context"        xmlns:p="http://www.springframework.org/schema/p"        xmlns:mvc="http://www.springframework.org/schema/mvc"        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        xsi:schemaLocation="        http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans.xsd        http://www.springframework.org/schema/aop        http://www.springframework.org/schema/aop/spring-aop.xsd        http://www.springframework.org/schema/tx        http://www.springframework.org/schema/tx/spring-tx.xsd        http://www.springframework.org/schema/context        http://www.springframework.org/schema/context/spring-context.xsd         http://www.springframework.org/schema/mvc        http://www.springframework.org/schema/mvc/spring-mvc.xsd">    <context:component-scan base-package="cn.hello.Conteller"></context:component-scan></beans>
@Controllerpublic class ArgumentConterller {    @RequestMapping("/login")    public  String login(){        return "/index2.jsp";    }    @RequestMapping("/login2")    public  String login2(Useinfo info){        System.out.println(info.getUname());        return "/index2.jsp";    }    @RequestMapping("/login3")    public  String login4(@RequestParam("uname") String n){        System.out.println(n);        return "/index2.jsp";    }    @RequestMapping("/Argen")    public  String login3(Useinfo info){        System.out.println(info.getUname()+"\t"+info.getBook().getBookName());        return "/index2.jsp";    }    @RequestMapping("/ListArgen")    public  String login4(Useinfo info){        System.out.println(info.getUname()+"\t"+info.getBooks().get(0).getBookName()+"\t"+info.getBooks().get(1).getBookName());        return "/index2.jsp";    }}
public class Book {    private String bookName;    public String getBookName() {        return bookName;    }    public void setBookName(String bookName) {        this.bookName = bookName;    }}

public class Useinfo {    private   String uname;    private  Book book;    private List<Book> books;    public List<Book> getBooks() {        return books;    }    public void setBooks(List<Book> books) {        this.books = books;    }    public Book getBook() {        return book;    }    public void setBook(Book book) {        this.book = book;    }    public String getUname() {        return uname;    }    public void setUname(String uname) {        this.uname = uname;    }}
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %><html><head>    <title>SpringMvc</title></head><body>    <form action="${pageContext.request.contextPath}/ListArgen" method="post">        用户名:<input name="uname"/>        图书名1:<input name="books[0].bookName"/>        图书名2:<input name="books[1].bookName"/>        <input type="submit"/>    </form></body></html>