mysql 数据库表结构
database javadb
table info
CREATE TABLE student
(
sid
int(11) NOT NULL AUTO_INCREMENT,
name
varchar(255) DEFAULT NULL,
sex
varchar(255) DEFAULT NULL,
age
int(11) DEFAULT NULL,
country
varchar(255) DEFAULT NULL,
data
text,
imgurl
varchar(1000) DEFAULT NULL,
PRIMARY KEY (sid
)
) ENGINE=InnoDB AUTO_INCREMENT=130042104 DEFAULT CHARSET=utf8 COMMENT=’学生表’;
jsp spring mvc
/WEB-INF/web.xml 配置
<?xml version="1.0" encoding="utf-8" ?>
<web-app>
<display-name>SpringMvc_demo1</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
<!-- 静态资源不进入springmvc处理 -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.swf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.xml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.json</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.map</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.txt</url-pattern>
</servlet-mapping>
<!-- 监听环境加载 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 监听requst请求环境 -->
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<!-- 环境变量 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/xml/spring-server.xml
</param-value>
</context-param>
<!-- SprngMvc1 servlet -->
<servlet>
<servlet-name>SpringMvc1</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/xml/springmvc-service.xml</param-value>
</init-param>
<on-load-startup>1</on-load-startup>
</servlet>
<!-- 处理请求 映射给spring mvc -->
<servlet-mapping>
<servlet-name>SpringMvc1</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
java 包
在src目录下 spring.xml.springmvc-service.xml spring mvc 环境配置
<?xml version="1.0" encoding="utf-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"
>
<context:component-scan base-package="web.app.controller" />
<mvc:annotation-driven />
<!-- 不处理静态资源 -->
<mvc:default-servlet-handler />
<!-- 配置内部资源视图解析器 -->
<bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 前缀 -->
<property name="prefix" value="/WEB-INF/view/" />
<!-- 后缀 -->
<property name="suffix" value=".jsp" />
</bean>
<!-- 支持上传文件 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8" />
<property name="maxUploadSize" value="5400000" />
</bean>
</beans>
src目录下 spring.xml.spring-server.xml spring 框架环境配置
<?xml version="1.0" encoding="utf-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"
>
<!-- mysql 数据库配置 -->
<import resource="mysql-db-driver-manager.xml" />
<!-- 开启注解监听 -->
<context:annotation-config />
<!-- 需要扫描的注解包 -->
<context:component-scan base-package="spring.beans" />
</beans>
spring.xml.mysql-db-driver-manager.xml 数据库配置dataSource
<?xml version="1.0" encoding="utf-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"
>
<!-- 解析数据库用户名和密码 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/spring/xml/database.properties</value>
</list>
</property>
</bean>
<!-- 数据库配置 - mysql - spring 方式 -->
<bean id="mysql_driver_manager_dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
</beans>
database.properties
#driver class path
jdbc.driverClassName=com.mysql.jdbc.Driver
#database driver connection url
jdbc.url=jdbc:mysql://localhost:3306/javadb?useUnicode=true&characterEncodong=utf-8
#database username
jdbc.username=xxxxx
#database password
jdbc.password=xxxxxxxxxxxxx
src 目录下创建接口DbOper 作用为以后更换数据库关于数据库的操作都继承自DbOper的操作接口
standard.db.operation.DbOper
package standard.db.operation;
import java.sql.Connection;
import java.util.List;
import java.util.Map;
import spring.beans.db.realization.mysql.DataType;
public interface DbOper
{
/**
* 数据库连接
* */
public void setConnection(Connection conn);
public Connection getConnection();
/**
* 查询所有数据
* @param
* String 要执行的sql语句
* @param
* String[] keyVal 映射数组
* @return
* List<Map<String,String>> result 查询结果集
* */
public List<Map<String,String>> query(String sql,String[] keyVal);
public List<Map<String,String>> query(String sql);
/**
* 查询单行数据
* @param
* String 要执行的sql语句
* @param
* String[] keyVal 映射数组
* @return
* Map<String,String> result 查询结果集
* */
public Map<String,String> find(String sql,String[] keyVal);
public Map<String,String> find(String sql);
/**
* 更新数据
* @param
* String 要执行的sql语句
* @param
* String[] keyVal 映射数组
* @return
* int resultInt 受影响的行数
* */
public int update(String sql,String[] keyVal);
public int update(String sql);
/**
* 新增数据
* @param
* String 要执行的sql语句
* @param
* String[] keyVal 映射数组
* @return
* int resultInt 新增成功行数
* */
public int insert(String sql,String[] keyVal);
public int insert(String sql);
/**
* 删除数据库
* @param
* String 要执行的sql语句
* @param
* String[] keyVal 映射数组
* @return
* boolean 删除时候成功
* */
public boolean delete(String sql,String[] keyVal);
public boolean delete(String sql);
/**
* 调用存储过程
* @param
* String callFunc 存储过程名称
* List<Map<String,String>> 存储过程参数值 如:Map<"int","22">
* */
public List<Map<String,String>> callResult(String callFunc,List<DataType> keyVal);
public List<Map<String,String>> callResult(String callFunc);
}
package spring.beans.db.realization.mysql.MysqlRealization;
package spring.beans.db.realization.mysql;
import java.sql.Connection;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.sql.CallableStatement;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.sql.DataSource;
import log.Log;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
import standard.db.operation.DbOper;
/**
* mysql 操作实现类 - 容器
* author : 谭勇
* create_date : 2017-04-13
* */
@Repository("db_connection")
@Scope("request")
public final class MysqlRealization implements DbOper
{
private Connection conn;
/**
* 对象初始化
* */
@PostConstruct
public void initDb()
{
}
@Override
public void setConnection(Connection conn)
{
this.conn = conn;
}
@Value(value="#{mysql_driver_manager_dataSource}")
public void setConnection(DataSource dataSource)
{
try{
setConnection(dataSource.getConnection());
}catch(SQLException e)
{
Log.e(e.getMessage());
}
}
@Override
public Connection getConnection()
{
return this.conn;
}
@Override
public List<Map<String, String>> query(String sql, String[] keyVal)
{
PreparedStatement pre = null;
ResultSet result = null;
ResultSetMetaData meta = null;
try{
pre = conn.prepareStatement(sql);
if(keyVal != null)
{
//映射到问号
for(int i=1;i<=keyVal.length;i++)
{
pre.setString(i, keyVal[i-1]);
}
}
result = pre.executeQuery();
if (result.next())
{
meta = result.getMetaData();
result.last();
List<Map<String,String>> list = new ArrayList<Map<String,String>>(result.getRow());
result.first();
int propertiesLength = meta.getColumnCount();
do{
Map<String,String> map = new HashMap<String,String>(propertiesLength);
for(int i=1;i<=propertiesLength;i++)
{
String keyName = meta.getColumnName(i);
map.put(keyName, result.getString(keyName));
}
list.add(map);
}while(result.next());
return list;
}
}catch(SQLException e)
{
Log.e(e.getMessage());
e.printStackTrace();
}finally{
closePreparedStatement(pre);
closeResultSet(result);
}
return null;
}
@Override
public List<Map<String, String>> query(String sql)
{
return query(sql,null);
}
@Override
public Map<String, String> find(String sql, String[] keyVal)
{
//Log.e(sql);
PreparedStatement pre = null;
ResultSet result = null;
ResultSetMetaData meta = null;
try{
pre = conn.prepareStatement(sql);
if(keyVal != null)
{
//映射到问号
for(int i=1;i<=keyVal.length;i++)
{
pre.setString(i, keyVal[i-1]);
}
}
result = pre.executeQuery();
if (result.next())
{
meta = result.getMetaData();
int propertiesLength = meta.getColumnCount();
Map<String,String> map = new HashMap<String,String>(propertiesLength);
for(int i=1;i<=propertiesLength;i++)
{
String keyName = meta.getColumnName(i);
map.put(keyName, result.getString(keyName));
}
return map;
}
}catch(SQLException e)
{
Log.e(e.getMessage());
e.printStackTrace();
}finally{
closePreparedStatement(pre);
closeResultSet(result);
}
return null;
}
@Override
public Map<String, String> find(String sql)
{
return find(sql,null);
}
@Override
public int update(String sql, String[] keyVal)
{
PreparedStatement pre = null;
try{
pre = conn.prepareStatement(sql);
if(keyVal != null)
{
//映射到问号
for(int i=1;i<=keyVal.length;i++)
{
pre.setString(i, keyVal[i-1]);
}
}
return pre.executeUpdate();
}catch(SQLException e)
{
Log.e(e.getMessage());
e.printStackTrace();
}finally{
closePreparedStatement(pre);
}
return 0;
}
@Override
public int update(String sql)
{
return update(sql,null);
}
@Override
public int insert(String sql, String[] keyVal)
{
PreparedStatement pre = null;
try{
pre = conn.prepareStatement(sql);
if(keyVal != null)
{
//映射到问号
for(int i=1;i<=keyVal.length;i++)
{
pre.setString(i, keyVal[i-1]);
}
}
return pre.executeUpdate();
}catch(SQLException e)
{
Log.e(e.getMessage());
e.printStackTrace();
}finally{
closePreparedStatement(pre);
}
return 0;
}
@Override
public int insert(String sql)
{
return insert(sql,null);
}
@Override
public boolean delete(String sql, String[] keyVal)
{
PreparedStatement pre = null;
try{
pre = conn.prepareStatement(sql);
if(keyVal != null)
{
//映射到问号
for(int i=1;i<=keyVal.length;i++)
{
pre.setString(i, keyVal[i-1]);
}
}
return pre.executeUpdate() > 0 ? true:false;
}catch(SQLException e)
{
Log.e(e.getMessage());
e.printStackTrace();
}finally{
closePreparedStatement(pre);
}
return false;
}
@Override
public boolean delete(String sql)
{
return delete(sql,null);
}
/**
* 调用存储过程
* @param
* String callFunc 存储过程名
* */
public List<Map<String,String>> callResult(String callFunc,List<DataType> keyVal)
{
String call = "{call " + callFunc + "}";
ResultSetMetaData meta = null;
CallableStatement callableStatement= null;
ResultSet result = null;
try{
callableStatement = conn.prepareCall(call);
if(keyVal != null)
{
for(int i=1;i<=keyVal.size();i++)
{
DataType data = keyVal.get(i-1);
switch(data.getType())
{
case ValueTypeSource.STRING:
callableStatement.setString(i, String.valueOf(data.getValue()));
break;
case ValueTypeSource.INT:
callableStatement.setInt(i, Integer.valueOf(data.getValue()));
break;
case ValueTypeSource.LONG:
callableStatement.setLong(i, Long.valueOf(data.getValue()));
break;
case ValueTypeSource.DOUBLE:
callableStatement.setDouble(i, Double.valueOf(data.getValue()));
break;
default:
callableStatement.setString(i,String.valueOf(data.getValue()));
}
}
}
callableStatement.execute();
result = callableStatement.getResultSet();
meta = result.getMetaData();
result.last();
List<Map<String,String>> list = new ArrayList<Map<String,String>>(result.getRow());
result.first();
int propertiesLength = meta.getColumnCount();
do{
Map<String,String> map = new HashMap<String,String>(propertiesLength);
for(int i=1;i<=propertiesLength;i++)
{
String keyName = meta.getColumnName(i);
map.put(keyName, result.getString(keyName));
}
list.add(map);
}while(result.next());
return list;
}catch(SQLException e)
{
e.printStackTrace();
return null;
}finally{
closeCallableStatement(callableStatement);
closeResultSet(result);
}
}
@Override
public List<Map<String,String>> callResult(String callFunc)
{
return callResult(callFunc,null);
}
/**
* 关闭资源链接
* */
private void closePreparedStatement(PreparedStatement pre)
{
if(pre != null)
{
try
{
pre.close();
}catch(SQLException e)
{
e.printStackTrace();
}
}
}
private void closeResultSet(ResultSet result)
{
if(result != null)
{
try
{
result.close();
}catch(SQLException e)
{
e.printStackTrace();
}
}
}
private void closeCallableStatement(CallableStatement call)
{
if(call != null)
{
try
{
call.close();
}catch(SQLException e)
{
e.printStackTrace();
}
}
}
private void closeConnection(Connection conn)
{
if(conn != null)
{
try
{
conn.close();
}catch(SQLException e)
{
e.printStackTrace();
}
}
}
/**
* 对象注销
* */
@PreDestroy
public void closeDb()
{
closeConnection(conn);
}
}
调用存储过程需要的工具类
spring.beans.db.realization.mysql.DataType
package spring.beans.db.realization.mysql;
public final class DataType
{
private String keyName;
private String value;
private int type;
public DataType(){}
public DataType(String keyName,String value,int type)
{
setKeyName(keyName);
setValue(value);
setType(type);
}
public void setKeyName(String keyName)
{
this.keyName = keyName;
}
public void setValue(String value)
{
this.value = value;
}
public void setType(int type)
{
this.type = type;
}
public String getKeyName()
{
return keyName;
}
public String getValue()
{
return value;
}
public int getType()
{
return type;
}
}
spring.beans.db.realization.mysql.ValueType
package spring.beans.db.realization.mysql;
public enum ValueType
{
INT(ValueTypeSource.INT),
STRING(ValueTypeSource.STRING),
DOUBLE(ValueTypeSource.DOUBLE),
CHAR(ValueTypeSource.CHAR),
DATE(ValueTypeSource.DATE),
BLOB(ValueTypeSource.BLOB),
LONG(ValueTypeSource.LONG);
private int type;
private ValueType(int type)
{
this.type = type;
}
public int getType()
{
return type;
}
}
spring.beans.db.realization.mysql.ValueTypeSource
package spring.beans.db.realization.mysql;
public final class ValueTypeSource
{
public final static int INT=1,
STRING=2,
DOUBLE=3,
CHAR=4,
DATE=5,
LONG=6,
BLOB=7;
}
至此mysql配置和mysql操作类结束
接下来是关于Student的服务
spring.beans.service.StudentService 前面我们已经在spring-service 添加了该包的解析(<context:component-scan base-package="spring.beans">
)
package spring.beans.service;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import model.Student;
import standard.db.operation.DbOper;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import tool.Config;
@Service("service_student")
@Scope("request")
public class StudentService
{
@Resource(name="db_connection")
private DbOper dbOper;
/**
* 获取某个学生信息
* @param
* String sid 学生sid
* @return
* Student student 学生信息
* */
public Student getStudent(String sid)
{
String sql = "select * from student where sid = ?";
String[] keyVal = new String[]{sid};
Map<String,String> student = dbOper.find(sql, keyVal);
if(student == null)
{
return null;
}
return new Student(student);
}
/**
* 获得一部分学生信息
* @param
* ing page 分页数
* List<Student> 学生信息
* */
public List<Student> getStudents(int page)
{
int limitStartIndex = (page - 1) * Config.pageSize;
String sql = "select * from student limit " + limitStartIndex+","+Config.pageSize;
List<Map<String,String>> list = dbOper.query(sql);
if(list == null)
{
return null;
}
List<Student> students = new ArrayList<Student>(list.size());
for(Map<String,String> student:list)
{
students.add(new Student(student));
}
return students;
}
}
tool.Config 类
package tool;
public class Config
{
public final static int pageSize = 10;
}
model.Student student 模型类
package model;
import java.util.Map;
public class Student
{
private String sid;
private String name;
private String sex;
private String age;
private String country;
private String data;
private String imgurl;
public Student(){}
public Student(String sid,String name,String sex,String age,String country,String data,String imgurl)
{
setSid(sid);
setName(name);
setSex(sex);
setAge(age);
setCountry(country);
setData(data);
setImgurl(imgurl);
}
public Student(Map<String,String> student)
{
setSid(student.get("sid"));
setName(student.get("name"));
setSex(student.get("sex"));
setAge(student.get("age"));
setCountry(student.get("country"));
setData(student.get("data"));
setImgurl(student.get("imgurl"));
}
public void setSid(String sid)
{
this.sid = sid;
}
public String getSid()
{
return this.sid;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setSex(String sex)
{
this.sex = sex;
}
public String getSex()
{
return sex;
}
public void setAge(String age)
{
this.age = age;
}
public String getAge()
{
return age;
}
public void setCountry(String country)
{
this.country = country;
}
public String getCountry()
{
return country;
}
public void setData(String data)
{
this.data = data;
}
public String getData()
{
return data;
}
public void setImgurl(String imgurl)
{
this.imgurl = imgurl;
}
public String getImgurl()
{
return imgurl;
}
}
前端响应控制
web.app.controller.IndexController 前面我们已经在springmvc-service.xml中添加了该包的解析
package web.app.controller;
import javax.annotation.Resource;
import model.Student;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import spring.beans.service.StudentService;
import java.util.List;
@Controller
@RequestMapping("Index")
@Scope("request")
public class IndexController
{
@Resource(name="service_student")
private StudentService studentService;
/**
* 首页方法
* @request
* */
@RequestMapping(value="index",method={RequestMethod.GET})
public ModelAndView index()
{
return new ModelAndView("Index/index","hello","hello world!");
}
/**
* 查看某一个学生的基本信息
* @request
* String sid 学生sid
* */
@RequestMapping(value="getStudent",method={RequestMethod.GET,RequestMethod.POST})
public ModelAndView getStudent(@RequestParam(value="sid",required=false,defaultValue="") String sid)
{
Student student = null;
if(!sid.equals(""))
{
student = studentService.getStudent(sid);
}
return new ModelAndView("Index/getStudent","student",student);
}
/**
* 获得多个学生的信息
* @request
* int page 分页数
* */
@RequestMapping(value="getStudents/{page}",method={RequestMethod.GET,RequestMethod.POST})
public ModelAndView getStudents(@PathVariable(value="page") int page)
{
return new ModelAndView("Index/getStudents","students",studentService.getStudents(page));
}
}
根据springmvc-service的配置我们可以发现模版解析的路径在/WEB-INF/view文件夹下面
/WEB-INF/view/Index/getStudent.jsp
<%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTPYE html>
<html>
<head>
<meta charset="tutf-8" />
<title>student info</title>
</head>
<body>
<!-- if else 模版语法 -->
<c:choose>
<c:when test="${!empty student}">
<p>学号:${student.sid}</p>
<p>姓名:${student.name}</p>
<p>性别:${student.sex}</p>
<p>年龄:${student.age}</p>
<p>简介:${student.data}</p>
</c:when>
<c:otherwise>
<p>没有找到相应的学生</p>
</c:otherwise>
</c:choose>
</body>
</html>
/WEB-INF/view/Index/getStudents.jsp
<%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>get students</title>
<style>
*{margin:0px;padding:0px;}
</style>
</head>
<body>
<c:choose>
<c:when test="${!empty students}">
<c:forEach items="${students}" var="student">
<div style="margin-top:20px;">
<p>学号:${student.sid}</p>
<p>姓名:${student.name}</p>
<p>性别:${student.sex}</p>
<p>年龄:${student.age}</p>
<p>简介:${student.data}</p>
</div>
</c:forEach>
</c:when>
<c:when test="${empty students}">
<p>娃哈哈哈哈</p>
</c:when>
<c:otherwise>
<p>没有相关分页的信息</p>
</c:otherwise>
</c:choose>
</body>
</html>
/WEB-INF/view/Index/index.jsp
<%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8" isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>hello world</title>
</head>
<body>
<p>${hello}</p>
</body>
</html>