引言:年年岁岁今朝,恍恍惚惚明晓。又是一年走过,但仿佛岁月走的更快了些,让人喘息不已。今日也是今年的开始,也是对节前的总结和审视。记得节前,找过一个同事来分享过阿里的内部架构,我们也从中受益匪浅,比如打算使用ElasticSearch做日志分析等。之前使用的JPA,也遇到一些问题,也打算走入MyBatis的阵营,趁此机会呢,就使用Maven搭建了一个简单SSM Demo,顺便行之成文,给各位分享了。
本文主要是基于Maven搭建的SSM框架,即Spring+ SpringMVC + MyBatis。本文将从创建项目开始,一步一步带你走入SSM框架世界。另外,本文Demo是基于Maven搭建,如果对Maven不熟悉的话,最好先找些资料看看,准备好环境。
一、准备和工具
1. 具备Java及Maven环境
2. 开发工具Eclipse(Version: Indigo Service Release 2)
3. 数据库MySql
二、创建项目
下面从使用Maven创建项目开始,循序渐进地引导您亲手完成整个项目的创建,不过本文只简单的介绍一下创建过程。
1. 新建项目
这里采用快捷的创建方式,勾上Create a simple project项,会生成基本的Maven项目结构。
2. 填写项目信息
填写Group Id、Artifact Id、Packaging即可,其他可不填。Group Id就类似包名,如com.stark,Artifact Id就是项目名称,Packaging项选择war即可。填完之后,直接Finish即可。生成的目录如下:
生成目录之后,最好先把项目的编码改为UTF-8。
3. 将把Maven Project转换为Dynamic Web Project
右击项目,选择“Properties”,再选择“Project Facets”,点击“Convert to faceted form…”,此时如下:
选择Dynamic Web Module,版本切换为2.5,再点击下方的“Further configuration available…”,会弹出应用目录的设置,如下:
将“WebContent”修改为“/src/main/webapp/”,如下,再点击OK。
点击“Apply”,此时您应该已经看到了项目已经变化了吧,此时已经变成了Dynamic Web Project项目了,与直接创建的Web项目的目录结构一样了。
4. 将JRE System Library修改为自己安装的JRE
同样的右击项目,选择“Properties”,再选择“Java Build Path”,先将原来的“JRE System Library[J2SE-1.5]”移除,再点击“ADD Library”,选择“JRE System Library”,下一步,默认选择的就是Workspace default JRE(jre6),点击Finish即可。
5. 修改Deployment Assembly
同样的右击项目,选择“Properties”,再选择“Deployment Assembly”,点击“ADD”按钮,在弹出框中选择“Java Build Path Entries”,点击“Next”,选择“Maven Dependencies”,最后Finish完成。点击“Apply”完成配置。
三、配置pom.xml
如下配置:
<project xmlns=”http://maven.apache.org/POM/4.0.0” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd“><modelVersion>4.0.0</modelVersion><groupId>com.stark</groupId><artifactId>stark-spring-springmvc-mybatis-demo</artifactId><version>0.0.1-SNAPSHOT</version><packaging>war</packaging><properties><!– spring版本号 –><spring.version>4.0.2.RELEASE</spring.version><!– mybatis版本号 –><mybatis.version>3.2.6</mybatis.version><mybatisspring.version>1.2.2</mybatisspring.version><!– log4j日志文件管理包版本 –><slf4j.version>1.7.7</slf4j.version><log4j.version>1.2.17</log4j.version></properties><dependencies><!– junit测试包 –><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><!– 表示开发的时候引入,发布的时候不会加载此包 –><scope>test</scope></dependency><!– spring核心包 –><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>${spring.version}</version></dependency><!– mybatis核心包 –><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>${mybatis.version}</version></dependency><!– mybatis/spring包 –><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>${mybatisspring.version}</version></dependency><!– druid jar –><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.0.9</version></dependency><!– 导入java ee jar 包 –><dependency><groupId>javax</groupId><artifactId>javaee-api</artifactId><version>7.0</version></dependency><!– 导入Mysql数据库链接jar包 –><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.30</version></dependency><!– JSTL标签类 –><dependency><groupId>jstl</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><!– 日志文件管理包 –><!– log start –><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>${log4j.version}</version></dependency><!– 格式化对象,方便输出日志 –><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.1.41</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>${slf4j.version}</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>${slf4j.version}</version></dependency><!– log end –><!– spring aop 支持jar –><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.8.8</version></dependency><!– 引入JSON –><dependency><groupId>org.codehaus.jackson</groupId><artifactId>jackson-mapper-asl</artifactId><version>1.9.13</version></dependency><!– 上传组件包 –><dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.3.1</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.4</version></dependency><dependency><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId><version>1.9</version></dependency></dependencies><build><plugins><plugin><artifactId>maven-compiler-plugin</artifactId><version>2.3.2</version><configuration><source>1.6</source><target>1.6</target></configuration></plugin><plugin><artifactId>maven-war-plugin</artifactId><version>2.2</version><configuration><version>3.0</version><failOnMissingWebXml>false</failOnMissingWebXml></configuration></plugin></plugins></build></project>
注:此时项目上可能会出现红叉,如果出现红叉,只要右击项目,选择“Maven”->“Update Project Configuration…”,默认是选择当前项目,直接点击OK即可,一会儿红叉就会消失了。
四、配置web.xml
内容如下:
<?xml version=”1.0″ encoding=”UTF-8″?><web-app xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns=”http://java.sun.com/xml/ns/javaee”xsi:schemaLocation=”http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd” id=”WebApp_ID” version=”2.5″><display-name>stark-spring-springmvc-mybatis-demo</display-name><!– 加载配置文件 –><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:application.xml</param-value></context-param><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param></filter><filter-mapping><filter-name>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><listener><description>spring listener</description><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><servlet><servlet-name>spring</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring-mvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>spring</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list></web-app>
以上主要配置,加载spring的配置和spring-mybatis的配置,添加了编码过滤器,还有最主要的spring servlet。
五、配置Spring、SpringMVC和MyBatis等
本文只是初步的搭建框架,没有详细的规划项目的目录结构等。首先先创建相关的package,再添加相关的配置文件,如下是创建完成后的目录结构:
1. 在“src/main/java”下创建相关目录结构
按上图的结构创建即可。
2. 在“src/main/resources”下添加application.properties文件
内容如下:
######数据库连接配置######jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/ssm-demo?useUnicode=true&characterEncoding=UTF-8jdbc.username=<用户名>jdbc.password=<用户密码>#配置初始连接数initialSize=0#配置最大连接数maxActive=20#配置最大空闲maxIdle=20#配置最小空闲minIdle=0#配置最长等待时间maxWait=60000#用来检测连接是否有效的sql,要求是一个查询语句validationQuery=SELECT ‘x’
3. 在“src/main/resources”添加log4j.properties文件
内容如下:
log4j.rootLogger=DEBUG,Console,Filelog4j.appender.Console=org.apache.log4j.ConsoleAppenderlog4j.appender.Console.Target=System.outlog4j.appender.Console.layout=org.apache.log4j.PatternLayoutlog4j.appender.Console.layout.ConversionPattern=[%c]%m%nlog4j.appender.File=org.apache.log4j.RollingFileAppenderlog4j.appender.File.File=spring-mybatis-demo.loglog4j.appender.File.MaxFileSize=10MBlog4j.appender.File.Threshold=ALLlog4j.appender.File.layout=org.apache.log4j.PatternLayoutlog4j.appender.File.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss,SSS}][%c]%m%n
4. 在“src/main/resources”添加spring-mvc.xml文件
内容如下:
<?xml version=”1.0″ encoding=”UTF-8″?><beans xmlns=”http://www.springframework.org/schema/beans” xmlns:mvc=”http://www.springframework.org/schema/mvc” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:p=”http://www.springframework.org/schema/p” xmlns:context=”http://www.springframework.org/schema/context” xsi:schemaLocation=”http://www.springframework.org/schema/beans<!– 扫描controller –><context:component-scan base-package=”com.stark.app.controller” /><!– 请求响应配置 –><bean id=”mappingJacksonHttpMessageConverter” class=”org.springframework.http.converter.json.MappingJacksonHttpMessageConverter”><property name=”supportedMediaTypes”><list><value>text/html;charset=UTF-8</value></list></property></bean><bean class=”org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter”><property name=”messageConverters”><list><ref bean=”mappingJacksonHttpMessageConverter” /></list></property></bean><!– jsp视图配置 –><bean id=”jspViewResolver” class=”org.springframework.web.servlet.view.InternalResourceViewResolver”><property name=”suffix” value=”.jsp” /></bean></beans>
以上主要配置了Controller的扫描注入、JSON格式的支持和视图层JSP的配置。
5. 在“src/main/resources”添加application.xml文件
内容如下:
<?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:tx=”http://www.springframework.org/schema/tx” xmlns:aop=”http://www.springframework.org/schema/aop”xmlns:context=”http://www.springframework.org/schema/context”xsi:schemaLocation=”<!– 加载config.properties –><context:property-placeholder location=”classpath:application.properties” /><!– 扫描service –><context:component-scan base-package=”com.stark.app.service” /><!– 使用druid数据源 –><bean id=”dataSource” class=”com.alibaba.druid.pool.DruidDataSource” init-method=”init” destroy-method=”close”><!– 可以不配置,根据url自动识别 –><property name=”driverClassName” value=”${jdbc.driverClassName}”></property><property name=”url” value=”${jdbc.url}” /><property name=”username” value=”${jdbc.username}” /><property name=”password” value=”${jdbc.password}” /><property name=”initialSize” value=”${initialSize}” /><property name=”maxActive” value=”${maxActive}” /><property name=”maxIdle” value=”${maxIdle}” /><property name=”minIdle” value=”${minIdle}” /><property name=”maxWait” value=”${maxWait}” /><property name=”validationQuery” value=”${validationQuery}” /><property name=”testOnBorrow” value=”false” /><property name=”testOnReturn” value=”false” /><property name=”testWhileIdle” value=”true” /><property name=”timeBetweenEvictionRunsMillis” value=”60000″ /><property name=”minEvictableIdleTimeMillis” value=”25200000″ /><property name=”removeAbandoned” value=”true” /><property name=”removeAbandonedTimeout” value=”1800″ /><property name=”logAbandoned” value=”true” /><property name=”filters” value=”mergeStat” /></bean><!– 生成SqlSessionFactory,其中使用通配符方式来加载相关的Mapper配置文件 –><bean id=”sqlSessionFactory” class=”org.mybatis.spring.SqlSessionFactoryBean”><property name=”dataSource” ref=”dataSource” /><property name=”mapperLocations” value=”classpath:com/stark/app/mappers/**/*Mapper.xml” /></bean><!– 扫描相关的Mapper接口 –><bean class=”org.mybatis.spring.mapper.MapperScannerConfigurer”><property name=”basePackage” value=”com/stark/app/mappers” /><property name=”sqlSessionFactoryBeanName” value=”sqlSessionFactory” /></bean><!– 以下是事务及AOP的配置 –><bean id=”transactionManager” class=”org.springframework.jdbc.datasource.DataSourceTransactionManager”><property name=”dataSource” ref=”dataSource” /></bean><tx:advice id=”transactionAdvice” transaction-manager=”transactionManager”><tx:attributes><tx:method name=”add*” propagation=”REQUIRED” /><tx:method name=”append*” propagation=”REQUIRED” /><tx:method name=”insert*” propagation=”REQUIRED” /><tx:method name=”save*” propagation=”REQUIRED” /><tx:method name=”update*” propagation=”REQUIRED” /><tx:method name=”modify*” propagation=”REQUIRED” /><tx:method name=”edit*” propagation=”REQUIRED” /><tx:method name=”delete*” propagation=”REQUIRED” /><tx:method name=”remove*” propagation=”REQUIRED” /><tx:method name=”repair” propagation=”REQUIRED” /><tx:method name=”delAndRepair” propagation=”REQUIRED” /><tx:method name=”get*” propagation=”SUPPORTS” /><tx:method name=”find*” propagation=”SUPPORTS” /><tx:method name=”load*” propagation=”SUPPORTS” /><tx:method name=”search*” propagation=”SUPPORTS” /><tx:method name=”datagrid*” propagation=”SUPPORTS” /><tx:method name=”*” propagation=”SUPPORTS” /></tx:attributes></tx:advice><aop:config><aop:pointcut id=”transactionPointcut” expression=”execution(* com.stark.app.service..*Impl.*(..))” /><aop:advisor pointcut-ref=”transactionPointcut” advice-ref=”transactionAdvice” /></aop:config></beans>
该文件配置了Spring Service层的扫描注入,Dao层使用MyBatis,另外,配置数据源,AOP及事务的处理。自然还有MyBatis的SqlSessonFactory的配置,此处托管于Spring来管理。
六、编码
主要涉及Controller、Service、Mapper(即Dao)、Model和JSP的展现。下面从底层开始建立,最终到JSP显示或JSON的显示。
1. model下新建User.java
内容如下:
package com.stark.app.model;/*** user model* @author stark*/public class User {private String id;private String name;private String password;private String state;private String description;/** set和get省略 **/}
2. mappers下新建UserMapper.java和UserMapper.xml
UserMapper内容如下:
package com.stark.app.mappers;import java.util.List;import java.util.Map;import com.stark.app.model.User;/*** 用户对象数据接口* @author stark*/public interface UserMapper {/*** 新增一条记录* @param vo* @return*/public int save(User vo);/*** 删除一条记录* @param id* @return*/public int delete(String id);/*** 更新一条记录* @param vo* @return*/public int modify(User vo);/*** 查询一条记录* @param id* @return*/public User findById(String id);/*** 根据map参数获取列表* @param map* @return*/public List<User> findAll(Map<String, Object> map);}
UserMapper.xml内容如下:
<?xml version=”1.0″ encoding=”UTF-8″ ?><!DOCTYPE mapper PUBLIC “-//mybatis.org//DTD Mapper 3.0//EN” “http://mybatis.org/dtd/mybatis-3-mapper.dtd” ><mapper namespace=”com.stark.app.mappers.UserMapper” ><resultMap type=”com.stark.app.model.User” id=”baseResultMap”><id column=”ID” property=”id” javaType=”java.lang.String” jdbcType=”VARCHAR” /><result column=”NAME” property=”name” javaType=”java.lang.String” jdbcType=”VARCHAR” /><result column=”PWD” property=”pwd” javaType=”java.lang.String” jdbcType=”VARCHAR” /><result column=”DESCRIPTION” property=”description” javaType=”java.lang.String” jdbcType=”VARCHAR” /><result column=”STATE” property=”state” javaType=”java.lang.String” jdbcType=”VARCHAR” /></resultMap><sql id=”user_attrs”>ID,NAME,PASSWORD,DESCRIPTION,STATE</sql><sql id=”user_vals”>#{id},#{name},#{password},#{description},#{state}</sql><insert id=”save” parameterType=”com.stark.app.model.User”>INSERT INTO USER (<include refid=”user_attrs”></include>)VALUES (<include refid=”user_vals”></include>)</insert><delete id=”delete” parameterType=”java.lang.String”>DELETE FROM USER WHERE ID = #{id}</delete><update id=”modify” parameterType=”com.stark.app.model.User”>UPDATE USER<set><if test=”name != null and name != ””>NAME = #{name},</if><if test=”password != null and password != ””>PASSWORD = #{password},</if><if test=”description != null and description != ””>DESCRIPTION = #{description},</if><if test=”state != null and state != ””>STATE = #{state}</if></set>WHERE ID = #{id}</update><select id=”findById” parameterType=”java.lang.String” resultMap=”baseResultMap”>SELECT <include refid=”user_attrs”></include>FROM USERWHERE ID = #{id}</select><select id=”findAll” parameterType=”java.util.Map” resultMap=”baseResultMap”>SELECT <include refid=”user_attrs”></include>FROM USER</select></mapper>
3. service下新建IUserService.java和UserServiceImpl.java
IUserService内容如下:
package com.stark.app.service;import java.util.List;import com.stark.app.model.User;public interface IUserService {/*** 保存User对象* @param vo* @return* @throws Exception*/public int saveVo(User vo) throws Exception;/*** 根据id删除对象* @param id* @throws Exception*/public int deleteVo(String id) throws Exception;/*** 修改对象* @param vo* @throws Exception*/public int modifyVo(User vo) throws Exception;/*** 根据id获取User对象* @param id* @return* @throws Exception*/public User findById(String id) throws Exception;/*** 查找所有的对象* @return* @throws Exception*/public List<User> findAll() throws Exception;}
UserServiceImpl内容如下:
package com.stark.app.service.impl;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import com.stark.app.mappers.UserMapper;import com.stark.app.model.User;import com.stark.app.service.IUserService;/*** User Service* @author stark*/@Service(“userService”)public class UserServiceImpl implements IUserService {@Autowiredprivate UserMapper userMapper;@Overridepublic int saveVo(User vo) throws Exception {int result = -1;try {result = this.userMapper.save(vo);} catch (Exception e) {throw new Exception(“新增出错!”);}return result;}@Overridepublic int deleteVo(String id) throws Exception {int result = -1;try {result = this.userMapper.delete(id);} catch (Exception e) {throw new Exception(“删除出错!”);}return result;}@Overridepublic int modifyVo(User vo) throws Exception {int result = -1;try {result = this.userMapper.modify(vo);} catch (Exception e) {throw new Exception(“修改出错!”);}return result;}@Overridepublic User findById(String id) throws Exception {User result = null;try {result = this.userMapper.findById(id);} catch (Exception e) {throw new Exception(“查询出错!”);}return result;}@Overridepublic List<User> findAll() throws Exception {List<User> result = new ArrayList<User>();try {result = this.userMapper.findAll(new HashMap<String, Object>());} catch (Exception e) {throw new Exception(“查询出错!”);}return result;}}
4. controller下新建UserController.java
UserController内容如下:
package com.stark.app.controller;import java.util.List;import java.util.UUID;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import com.stark.app.model.User;import com.stark.app.service.IUserService;/*** User Controller* @author stark*/@Controller@RequestMapping(“/user/”)public class UserController {@Autowiredprivate IUserService userService;/*** 新增用户,并返回新增之后的用户信息* @param request* @param response* @param model* @return* @throws Exception*/@RequestMapping(value=”/addUser.do”)public String addUser(HttpServletRequest request, HttpServletResponse response,Model model) throws Exception{String name = request.getParameter(“name”);String pwd =request.getParameter(“pwd”);User user = new User();user.setId(UUID.randomUUID().toString());//使用UUIDuser.setName(name);user.setPassword(pwd);this.userService.saveVo(user);model.addAttribute(“user”, user);return “/WEB-INF/jsp/result”;}/*** 根据id获取用户信息* @param request* @return* @throws Exception*/@ResponseBody@RequestMapping(value=”/getUser.do”)public Object loadUser(HttpServletRequest request) throws Exception{String id = request.getParameter(“id”);User user = this.userService.findById(id);return user;}/*** 获取所有的用户列表* @param request* @return* @throws Exception*/@ResponseBody@RequestMapping(value=”/getUserlist.do”)public Object userList(HttpServletRequest request) throws Exception{//查询数据List<User> userList = this.userService.findAll();return userList;}}
5. “WEB-INF/jsp/”下新建result.jsp
result.jsp内容如下:
<%@ page language=”java” contentType=”text/html; charset=utf-8″ pageEncoding=”UTF-8″%><!DOCTYPE html><html><head><meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″><title>add success</title></head><body><div>ID:${user.id}</div><div>Name:${user.name}</div></body></html>
七、测试
1. 数据库准备
在MySql中创建名为ssm-demo的数据库,再创建USER表。
创建SQL语句:
CREATE TABLE `user` (`ID` varchar(36) NOT NULL,`NAME` varchar(50) DEFAULT NULL,`PASSWORD` varchar(50) DEFAULT NULL,`DESCRIPTION` varchar(200) DEFAULT NULL,`STATE` varchar(2) DEFAULT NULL,PRIMARY KEY (`ID`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2.新增User
在浏览器中输入URL:<项目路径>/user/addUser.do?name=test&pwd=123456,会返回结果页面,可测试页面的跳转及新增功能。
如下:
3.根据ID获取一个User
在浏览器中输入URL:<项目路径>/user/getUser.do?id=,会以JSON的格式显示。
如下:
4.获取所有的User
在浏览器中输入URL:<项目路径>/user/getUserlist.do,会以JSON的格式显示。
如下:
至此编码的测试也尾声了。
如有问题,欢迎指出;如需转载,请标明出处,谢谢!
参考资料