热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

SpringMVC实现查询功能

1web.xml2springmvc.xml3实体类com.springmvc.crud.entities4 com.springmvc.crud.dao5控制器 com.spri

1 web.xml

 1 
 2  3     xmlns="http://java.sun.com/xml/ns/javaee"
 4     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 5     id="WebApp_ID" version="2.5">
 6 
 7     
 8     
 9         HiddenHttpMethodFilter
10         class>org.springframework.web.filter.HiddenHttpMethodFilterclass>
11     
12     
13         HiddenHttpMethodFilter
14         /*
15     
16     
17     
18     
19         springDispatcherServlet
20         org.springframework.web.servlet.DispatcherServlet
21         
22             contextConfigLocation
23             classpath:springmvc.xml
24         
25         1
26     
27 
28     
29     
30         springDispatcherServlet
31         /
32     
33 

2 springmvc.xml

 1 
 2  3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xmlns:c="http://www.springframework.org/schema/c"
 5     xmlns:aop="http://www.springframework.org/schema/aop"
 6     xmlns:cOntext="http://www.springframework.org/schema/context"
 7     xmlns:mvc="http://www.springframework.org/schema/mvc"
 8     xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
 9         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
10         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
11         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">
12     
13     
14     package="com.springmvc">
15 
16     
17     class="org.springframework.web.servlet.view.InternalResourceViewResolver">
18         
19         
20     
21     
22     
23     default-servlet-handler/>
24     
25     
26 
27 

3 实体类com.springmvc.crud.entities

 1 package com.springmvc.crud.entities;
 2 
 3 import java.util.Date;
 4 
 5 public class Employee {
 6 
 7     private Integer id;
 8     private String lastName;
 9     private String email;
10     //1 male, 0 female
11     private Integer gender;
12     
13     private Date birth;
14     private Float salary;
15 
16     public Integer getId() {
17         return id;
18     }
19 
20     public void setId(Integer id) {
21         this.id = id;
22     }
23 
24     public String getLastName() {
25         return lastName;
26     }
27 
28     public void setLastName(String lastName) {
29         this.lastName = lastName;
30     }
31 
32     public String getEmail() {
33         return email;
34     }
35 
36     public void setEmail(String email) {
37         this.email = email;
38     }
39 
40     public Integer getGender() {
41         return gender;
42     }
43 
44     public void setGender(Integer gender) {
45         this.gender = gender;
46     }
47 
48     public Date getBirth() {
49         return birth;
50     }
51 
52     public void setBirth(Date birth) {
53         this.birth = birth;
54     }
55 
56     public Float getSalary() {
57         return salary;
58     }
59 
60     public void setSalary(Float salary) {
61         this.salary = salary;
62     }
63 
64     @Override
65     public String toString() {
66         return "Employee [id=" + id + ", lastName=" + lastName + ", email="
67                 + email + ", gender=" + gender 
68                 + ", birth=" + birth + ", salary=" + salary + "]";
69     }
70 
71     public Employee(Integer id, String lastName, String email, Integer gender) {
72         super();
73         this.id = id;
74         this.lastName = lastName;
75         this.email = email;
76         this.gender = gender;
77     }
78 
79     public Employee() {
80     }
81 }

4 com.springmvc.crud.dao

 1 package com.springmvc.crud.dao;
 2 
 3 import java.util.Collection;
 4 import java.util.HashMap;
 5 import java.util.Map;
 6 
 7 import org.springframework.beans.factory.annotation.Autowired;
 8 import org.springframework.stereotype.Repository;
 9 
10 import com.springmvc.crud.entities.Employee;
11 
12 @Repository
13 public class EmployeeDao {
14     
15     private static Map employees=null;
16     
17     /*@Autowired
18     private DepartmentDao departmentDao;*/
19     
20     static{
21         employees = new HashMap();
22         
23         employees.put(1001, new Employee(1001, "E-AA", "aa@163.com", 1));
24         employees.put(1002, new Employee(1002, "E-BB", "bb@163.com", 1));
25         employees.put(1003, new Employee(1003, "E-CC", "cc@163.com", 0));
26         employees.put(1004, new Employee(1004, "E-DD", "dd@163.com", 0));
27         employees.put(1005, new Employee(1005, "E-EE", "ee@163.com", 1));
28     }
29     
30     private static Integer initId=1006;
31     
32     public void save(Employee employee){
33         if(employee.getId()==null){
34             employee.setId(initId++);
35         }
36         //employee.setDepartment(departmentDao.getDepartment(employee.getDepartment().getId()));
37         employees.put(employee.getId(), employee);
38     }
39     
40     public Collection getAll(){
41         return employees.values();
42     }
43     public Employee get(Integer id){
44         return employees.get(id);
45     }
46     
47     public void delete(Integer id ){
48         employees.remove(id);
49     }
50     
51     
52 }

5  控制器 com.springmvc.crud.handler

 1 package com.springmvc.crud.handler;
 2 
 3 import java.util.Map;
 4 
 5 import org.springframework.beans.factory.annotation.Autowired;
 6 import org.springframework.stereotype.Controller;
 7 import org.springframework.web.bind.annotation.RequestMapping;
 8 
 9 import com.springmvc.crud.dao.EmployeeDao;
10 
11 @Controller
12 public class EmployeeHandler {
13 
14     @Autowired
15     private EmployeeDao employeeDao;
16     
17     @RequestMapping("/listAll")
18     public String list(Map map){
19         map.put("employees",employeeDao.getAll());
20         return "list";
21     }
22 }

6 WEB-INF/views/list.jsp

 1 <%@ page language="java" cOntentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 4 
 5 
 6 
 7 
 8 
 9 
10 
11     121314151617181920
21             22232425262728
ID LastName Email Gender
${emp.id } ${emp.lastName } ${emp.email } ${emp.gender==0? ‘male‘ : ‘female‘ }
29 30

 技术分享

SpringMVC实现查询功能


推荐阅读
  • 猫猫分享,必须精品原文地址:http:blog.csdn.netu013357243articledetails44571163素材地址:http:download.csdn.n ... [详细]
  • MyBatis模糊查询和多条件查询一、ISmbmsUserDao层根据姓名模糊查询publicListgetUser();多条件查询publicList ... [详细]
  • 软件自动化测试的学习路线
    软件自动化测试的学习步骤软件测试交流群关注软件测试技术公众号获取阅读目录软件自动化测试的学习步骤自动化测试的本质自动化测试学习的误区自动化测试的职位自动化测试分类Web自动化 ... [详细]
  • ajax 跨域webapi 最简单的demo(只介绍Get)
    这几天遇到一个nodejs的项目,使用VSCode开发,需要连接数据库的,但是用nodejs连接数据库比较繁琐,需要安装很多 ... [详细]
  • 以SOA服务为导向的信息系统构建是通过有计划地构建信息系统时,一种简单而有柔性的方法,就是组件化与服务导向架构。过去的信息系统,是在使用者需要新功能时才开发的,也就是响应不同时 ... [详细]
  • 接口测试的方式有很多,比如可以用工具(jmeter,postman)之类,也可以自己写代码进行接口测试,工具的使用相对来说都比较简单,重点是要搞清楚项目接口的协议是什么,然后有针对 ... [详细]
  • Linux     系统安装
    Linux系统安装linux系统安装准备工作电脑、u盘、光盘、网络、硬盘主要使用光盘、网络虚拟化软件vmwarevi ... [详细]
  • 开发网站你需要知晓的部分专用术语
      越来越多的企业和个人都在拥有属于自己的网站门户,首当其冲的就是你得知晓几个网站方面的专业术语,先是中就有好多的客户不明白这些,造成误会是正常的,那不如我们对它有个大致的了解,这样就不容易感觉 ... [详细]
  • 九宫格计算. ... [详细]
  • Java开发框架!Alibaba高并发业务秒杀系统落地实战文档,砥砺前行!
    接口概述:接口是Java语言中的一种引用类型,是方法的集合,所以接口的内部主要就是定义方法,包含常量,抽象方法(JDK ... [详细]
  • C#的Type对象的简单应用
    通过Type对象可以获取类中所有的公有成员直接贴代码:classMyClass{privatestringname;privateintid;publicstringcity;pu ... [详细]
  • 作业迁移
    背景:数据库服务器更换,1、数据库迁移(BACKUPRESTORE);2、数据库登录名用户迁移(注意孤立用户);3、作业迁移数据库迁移,备份数据库、拷贝备份文件到新服务器,还原数据 ... [详细]
  • 定义:定义两个数论函数\(f\)、\(g\)的Dirichlet卷积为:\[\left(f*g\right)\left(n\right)\sum_{d|n}f\left(d\rig ... [详细]
  • rbac 4表 常规设计
    rbac4表常规设计设计模型:1、管理员表(users)Schema::create('users',function(Blueprint$table){$tabl ... [详细]
  • packagetest;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.IOE ... [详细]
author-avatar
grafopenshaw_460
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有