Spring MVC注解开发

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans  xmlns="http://www.springframework.org/schema/beans"  
  3.         xmlns:aop="http://www.springframework.org/schema/aop"  
  4.         xmlns:tx="http://www.springframework.org/schema/tx"  
  5.         xmlns:context="http://www.springframework.org/schema/context"  
  6.         xmlns:p="http://www.springframework.org/schema/p"  
  7.         xmlns:mvc="http://www.springframework.org/schema/mvc"  
  8.         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  9.         xsi:schemaLocation="  
  10.         http://www.springframework.org/schema/beans  
  11.         http://www.springframework.org/schema/beans/spring-beans.xsd  
  12.         http://www.springframework.org/schema/aop  
  13.         http://www.springframework.org/schema/aop/spring-aop.xsd  
  14.         http://www.springframework.org/schema/tx  
  15.         http://www.springframework.org/schema/tx/spring-tx.xsd  
  16.         http://www.springframework.org/schema/context  
  17.         http://www.springframework.org/schema/context/spring-context.xsd  
  18.          http://www.springframework.org/schema/mvc  
  19.         http://www.springframework.org/schema/mvc/spring-mvc.xsd  
  20. ">  
  21.     <context:component-scan base-package="cn.hello.Conteller"></context:component-scan>  
  22.   
  23. </beans>  
[java]  view plain  copy
  1. @Controller  
  2. @RequestMapping("/user")//指定的 路径名  
  3. public class Conterller {  
  4.    @RequestMapping("/{runame}/{uage}/fist")//访问 请求 路径 携带值  
  5.     public String insert(@PathVariable("runame")String uname,@PathVariable String uage){  
  6.        System.out.println(uname);  
  7.        System.out.println(uage);  
  8.           return "/insert.jsp";  
  9.     }  
  10.     @RequestMapping("/two")  
  11.     public String delete(){  
  12.         return "/delete.jsp";  
  13.     }  
  14.   
  15.     @RequestMapping("/*third")  
  16.     public String delete2(){  
  17.         //逻辑视图  
  18.         return "/delete.jsp";  
  19.     }  
  20.     @RequestMapping("/**/four")  
  21.     public String delete3(){  
  22.         return "/delete.jsp";  
  23.     }  
  24.     @RequestMapping("/*/five")  
  25.     public String delete4(){  
  26.         return "/delete.jsp";  
  27.     }  
  28.   
  29.   
  30. }  
[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans  xmlns="http://www.springframework.org/schema/beans"  
  3.         xmlns:aop="http://www.springframework.org/schema/aop"  
  4.         xmlns:tx="http://www.springframework.org/schema/tx"  
  5.         xmlns:context="http://www.springframework.org/schema/context"  
  6.         xmlns:p="http://www.springframework.org/schema/p"  
  7.         xmlns:mvc="http://www.springframework.org/schema/mvc"  
  8.         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  9.         xsi:schemaLocation="  
  10.         http://www.springframework.org/schema/beans  
  11.         http://www.springframework.org/schema/beans/spring-beans.xsd  
  12.         http://www.springframework.org/schema/aop  
  13.         http://www.springframework.org/schema/aop/spring-aop.xsd  
  14.         http://www.springframework.org/schema/tx  
  15.         http://www.springframework.org/schema/tx/spring-tx.xsd  
  16.         http://www.springframework.org/schema/context  
  17.         http://www.springframework.org/schema/context/spring-context.xsd  
  18.          http://www.springframework.org/schema/mvc  
  19.         http://www.springframework.org/schema/mvc/spring-mvc.xsd  
  20. ">  
  21.     <context:component-scan base-package="cn.hello.Conteller"></context:component-scan>  
  22.   
  23. </beans>  
[java]  view plain  copy
  1. @Controller  
  2. public class ArgumentConterller {  
  3.     @RequestMapping("/login")  
  4.     public  String login(){  
  5.         return "/index2.jsp";  
  6.     }  
  7.   
  8.     @RequestMapping("/login2")  
  9.     public  String login2(Useinfo info){  
  10.         System.out.println(info.getUname());  
  11.         return "/index2.jsp";  
  12.     }  
  13.   
  14.     @RequestMapping("/login3")  
  15.     public  String login4(@RequestParam("uname") String n){  
  16.         System.out.println(n);  
  17.         return "/index2.jsp";  
  18.     }  
  19.   
  20.   
  21.     @RequestMapping("/Argen")  
  22.     public  String login3(Useinfo info){  
  23.         System.out.println(info.getUname()+"\t"+info.getBook().getBookName());  
  24.         return "/index2.jsp";  
  25.     }  
  26.   
  27.     @RequestMapping("/ListArgen")  
  28.     public  String login4(Useinfo info){  
  29.         System.out.println(info.getUname()+"\t"+info.getBooks().get(0).getBookName()+"\t"+info.getBooks().get(1).getBookName());  
  30.         return "/index2.jsp";  
  31.     }  
  32. }  
[java]  view plain  copy
  1. public class Book {  
  2.     private String bookName;  
  3.   
  4.     public String getBookName() {  
  5.         return bookName;  
  6.     }  
  7.   
  8.     public void setBookName(String bookName) {  
  9.         this.bookName = bookName;  
  10.     }  
  11. }  

[java]  view plain  copy
  1. public class Useinfo {  
  2.     private   String uname;  
  3.   
  4.     private  Book book;  
  5.   
  6.     private List<Book> books;  
  7.   
  8.     public List<Book> getBooks() {  
  9.         return books;  
  10.     }  
  11.   
  12.     public void setBooks(List<Book> books) {  
  13.         this.books = books;  
  14.     }  
  15.   
  16.     public Book getBook() {  
  17.         return book;  
  18.     }  
  19.   
  20.     public void setBook(Book book) {  
  21.         this.book = book;  
  22.     }  
  23.   
  24.     public String getUname() {  
  25.         return uname;  
  26.     }  
  27.   
  28.     public void setUname(String uname) {  
  29.         this.uname = uname;  
  30.     }  
  31. }  
[html]  view plain  copy
  1. <%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>  
  2. <html>  
  3. <head>  
  4.     <title>SpringMvc</title>  
  5. </head>  
  6. <body>  
  7.     <form action="${pageContext.request.contextPath}/ListArgen" method="post">  
  8.         用户名:<input name="uname"/>  
  9.         图书名1:<input name="books[0].bookName"/>  
  10.         图书名2:<input name="books[1].bookName"/>  
  11.         <input type="submit"/>  
  12.     </form>  
  13. </body>  
  14. </html>  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值