一、数据结构设计:
测试用户表:test_user |
|||||
字段名 |
类型 |
长度 |
允许为空 |
默认值 |
描述 |
id |
varchar |
50 |
否 |
|
主键UUID |
name |
varchar |
30 |
否 |
|
姓名 |
|
varchar |
30 |
|
|
QQ号 |
|
varchar |
30 |
|
|
邮箱地址 |
phone |
varchar |
15 |
|
|
联系方式 |
createUser |
varchar |
30 |
|
|
创建人id |
createDate |
datetime |
|
|
|
创建日期 |
updateUser |
varchar |
30 |
|
|
更新人id |
updateDate |
datetime |
|
|
|
更新日期 |
deleteFlag |
bit |
1 |
否 |
1 |
0删除、1未删除 |
2.1、JavaBean代码
package com.xt.web.bean;
import org.apache.commons.lang.builder.ToStringBuilder;
import com.dwz.framework.support.bean.BaseBean;
/**
* 用户表对应的javabean
* @authormengxin 2015/06/17
*/
public classTestUser extendsBaseBean {
private static final long serialVersionUID= 1L;
privateStringname;
privateStringqq;
privateStringemail;
privateStringphone;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getQq() {
return qq;
}
public void setQq(String qq) {
this.qq = qq;
}
public String getEmail() {
return email;
}
public void setEmail(String email){
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone){
this.phone = phone;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
package com.xintu.manager.web.bean.controller;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.dwz.framework.support.controller.BasePageController;
import com.dwz.framework.support.page.PagerForm;
import com.xintu.manager.web.bean.TestUser;
import com.xintu.manager.web.bean.service.ITestUserService;
/**
* 用户表对应的controller
* @authormengxin 2015/06/17
*
*/
@Controller
@RequestMapping("/testUser")
public classTestUserController extends BasePageController
private static Logger logger = Logger.getLogger(TestUserController.class);
private ITestUserServicetestUserService;
@Autowired
publicTestUserController(ITestUserService testUserService) {
super(testUserService);
this.testUserService =testUserService;
}
/**
* 添加保存数据
* 返回页面时给出提示成功或失败信息
*/
@RequestMapping("/add")
@Override
public ModelAndView toAdd(@ModelAttribute TestUserinstance, HttpServletRequest request) {
//初始化baseBean信息
super.initCreateBaseBean(instance,null);
logger.info(instance.toString());
ModelAndViewmodelAndView = super.ajaxDoneError(getMessage("msg.operation.failure"));
//将instance中非null的属性保存到数据库中,返回1表求成功,返回0表示失败
int ret =this.testUserService.addColumnsNotNull(instance);
if(ret==1){
modelAndView= ajaxDoneSuccess(getMessage("msg.operation.success"));
}else{
logger.error("toAdd error !!!!");
}
return modelAndView;
}
/**
* 编辑保存数据
* 返回页面时给出提示成功或失败信息
*/
@RequestMapping("/edit")
@Override
public ModelAndViewtoEdit(TestUser instance, HttpServletRequest request) {
super.initUpdateBaseBean(instance,null);
logger.info(instance.toString());
ModelAndViewmodelAndView = ajaxDoneError(getMessage("msg.operation.failure"));
//将instance中非null的属性更新到数据库中,返回1表求成功,返回0表示失败
int ret =this.testUserService.updateColumnsNotNull(instance);
if(ret==1){
modelAndView= ajaxDoneSuccess(getMessage("msg.operation.success"));
}else{
logger.error("toEdit error !!!! ret : "+ret);
}
return modelAndView;
}
/**
* 进入添加页面
*/
@RequestMapping("/toAddPage")
@Override
public StringgotoAddPage(Model model) {
return "TestUser/add";
}
/**
* 进入编辑页面
*/
@RequestMapping("/toEditPage")
@Override
public String gotoEditPage(@RequestParam(value="id") String id,Model model) {
logger.info("id = "+id);
TestUserinstance = this.testUserService.get(id);
model.addAttribute("instance",instance);
return "TestUser/edit";
}
/**
* 进入预览页面
*/
@RequestMapping("/toViewPage")
@Override
public String gotoViewPage(@RequestParam(value="id") String id,Model model) {
logger.info("id = "+id);
TestUserinstance = this.testUserService.get(id);
model.addAttribute("instance",instance);
return "TestUser/view";
}
/**
* 进入列表展示页面
*/
@RequestMapping("/toListPage")
@Override
public String toListPage(@ModelAttribute PagerFormpagerForm,
HttpServletRequestrequest,
@RequestParam(required=false, defaultValue="", value="conditions")String conditions,
Modelmodel) {
//如果返回页面内容较复杂,可以参照initListPageModel自己实现
super.initListPageModel(this.testUserService, pagerForm,request, conditions,false, model);
return "TestUser/list";
}
/**
* 查询显示回收站内的列表数据
*/
@RequestMapping("/toGCListPage")
@Override
public String toGCListPage(@ModelAttribute PagerFormpagerForm,
HttpServletRequestrequest,
@RequestParam(required=false, defaultValue="", value="conditions")String conditions,
Modelmodel) {
//如果返回页面内容较复杂,可以参照initListPageModel自己实现
super.initListPageModel(this.testUserService, pagerForm,request, conditions,true, model);
return "TestUser/list";
}
}
2.3、IService代码
package com.xintu.manager.web.bean.service;
import com.dwz.framework.support.service.IBaseQueryService;
import com.xintu.manager.web.bean.TestUser;
/**
* service接口
* @authormengxin 2015/06/17
*
*/
public interfaceITestUserService extends IBaseQueryService
}
2.4、ServiceImpl代码
package com.xintu.manager.web.bean.service.impl;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dwz.framework.support.service.SupportPageInfoServiceDone;
import com.xintu.manager.web.bean.TestUser;
import com.xintu.manager.web.bean.mapper.TestUserMapper;
import com.xintu.manager.web.bean.service.ITestUserService;
/**
* 逻辑实现类
* @authormengxin 2015/06/17
*
*/
@Service("testUserService")
public classTestUserServiceImpl extends SupportPageInfoServiceDone
private static Logger logger = Logger.getLogger(TestUserServiceImpl.class);
private TestUserMappertestUserMapper;
@Autowired
publicTestUserServiceImpl(TestUserMapper testUserMapper) {
super(testUserMapper);
this.testUserMapper =testUserMapper;
}
@Override
public int deleteInLogic(Stringid) {
TestUserbean = newTestUser();
bean.setId(id);
bean.setDeleteFlag(0);
logger.info("deleteInLogic id : "+id);
return this.testUserMapper.updateByPrimaryKeySelective(bean);
}
@Override
public int recovery(String id) {
TestUserbean = newTestUser();
bean.setId(id);
bean.setDeleteFlag(1);
logger.info("recovery id : "+id);
return this.testUserMapper.updateByPrimaryKeySelective(bean);
}
}
package com.xintu.manager.web.bean.mapper;
import com.dwz.framework.support.mapper.BaseSupportListMapper;
import com.xintu.manager.web.bean.TestUser;
/**
* 用户mapper类
* @authormengxin 2015/06/17
*
*/
public interfaceTestUserMapper extends BaseSupportListMapper
}
2.6、mapping XML配置,可以用mybatis-generator-core-1.3.2.jar来自动生成
xmlversion="1.0"encoding="UTF-8"?>
DOCTYPEmapperPUBLIC"-//mybatis.org//DTDMapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mappernamespace="com.xintu.manager.web.bean.mapper.TestUserMapper">
<resultMapid="BaseResultMap"type="com.xintu.manager.web.bean.TestUser">
<idcolumn="id"property="id"jdbcType="VARCHAR"/>
<resultcolumn="name"property="name"jdbcType="VARCHAR"/>
<resultcolumn="qq"property="qq"jdbcType="VARCHAR"/>
<resultcolumn="email"property="email"jdbcType="VARCHAR"/>
<resultcolumn="phone"property="phone"jdbcType="VARCHAR"/>
<resultcolumn="createUser"property="createUser"jdbcType="VARCHAR"/>
<resultcolumn="createDate"property="createDate"jdbcType="TIMESTAMP"/>
<resultcolumn="updateUser"property="updateUser"jdbcType="VARCHAR"/>
<resultcolumn="updateDate"property="updateDate"jdbcType="TIMESTAMP"/>
<resultcolumn="deleteFlag"property="deleteFlag"jdbcType="INTEGER"/>
resultMap>
<sqlid="Base_Column_List">
id, name, qq, email, phone, createUser, createDate, updateUser,updateDate, deleteFlag
sql>
<selectid="selectByPrimaryKey"resultMap="BaseResultMap"parameterType="java.lang.String">
select
<includerefid="Base_Column_List"/>
from test_user
where id = #{id,jdbcType=VARCHAR}
select>
<deleteid="deleteByPrimaryKey"parameterType="java.lang.String">
delete from test_user
where id = #{id,jdbcType=VARCHAR}
delete>
<insertid="insert"parameterType="com.xintu.manager.web.bean.TestUser">
insert into test_user (id, name, qq,
email, phone, createUser,
createDate, updateUser, updateDate,
deleteFlag)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{qq,jdbcType=VARCHAR},
#{email,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},#{createUser,jdbcType=VARCHAR},
#{createDate,jdbcType=TIMESTAMP}, #{updateUser,jdbcType=VARCHAR},#{updateDate,jdbcType=TIMESTAMP},
#{deleteFlag,jdbcType=INTEGER})
insert>
<insertid="insertSelective"parameterType="com.xintu.manager.web.bean.TestUser">
insert into test_user
<trimprefix="("suffix=")"suffixOverrides=",">
<iftest="id != null">
id,
if>
<iftest="name != null">
name,
if>
<iftest="qq != null">
qq,
if>
<iftest="email != null">
email,
if>
<iftest="phone != null">
phone,
if>
<iftest="createUser != null">
createUser,
if>
<iftest="createDate != null">
createDate,
if>
<iftest="updateUser != null">
updateUser,
if>
<iftest="updateDate != null">
updateDate,
if>
<iftest="deleteFlag != null">
deleteFlag,
if>
trim>
<trimprefix="values ("suffix=")"suffixOverrides=",">
<iftest="id != null">
#{id,jdbcType=VARCHAR},
if>
<iftest="name != null">
#{name,jdbcType=VARCHAR},
if>
<iftest="qq != null">
#{qq,jdbcType=VARCHAR},
if>
<iftest="email != null">
#{email,jdbcType=VARCHAR},
if>
<iftest="phone != null">
#{phone,jdbcType=VARCHAR},
if>
<iftest="createUser != null">
#{createUser,jdbcType=VARCHAR},
if>
<iftest="createDate != null">
#{createDate,jdbcType=TIMESTAMP},
if>
<iftest="updateUser != null">
#{updateUser,jdbcType=VARCHAR},
if>
<iftest="updateDate != null">
#{updateDate,jdbcType=TIMESTAMP},
if>
<iftest="deleteFlag != null">
#{deleteFlag,jdbcType=INTEGER},
if>
trim>
insert>
<updateid="updateByPrimaryKeySelective"parameterType="com.xintu.manager.web.bean.TestUser">
update test_user
<set>
<iftest="name != null">
name = #{name,jdbcType=VARCHAR},
if>
<iftest="qq != null">
qq = #{qq,jdbcType=VARCHAR},
if>
<iftest="email != null">
email = #{email,jdbcType=VARCHAR},
if>
<iftest="phone != null">
phone = #{phone,jdbcType=VARCHAR},
if>
<iftest="createUser != null">
createUser = #{createUser,jdbcType=VARCHAR},
if>
<iftest="createDate != null">
createDate =#{createDate,jdbcType=TIMESTAMP},
if>
<iftest="updateUser != null">
updateUser =#{updateUser,jdbcType=VARCHAR},
if>
<iftest="updateDate != null">
updateDate =#{updateDate,jdbcType=TIMESTAMP},
if>
<iftest="deleteFlag != null">
deleteFlag =#{deleteFlag,jdbcType=INTEGER},
if>
set>
where id = #{id,jdbcType=VARCHAR}
update>
<updateid="updateByPrimaryKey"parameterType="com.xintu.manager.web.bean.TestUser">
update test_user
set name = #{name,jdbcType=VARCHAR},
qq = #{qq,jdbcType=VARCHAR},
email = #{email,jdbcType=VARCHAR},
phone = #{phone,jdbcType=VARCHAR},
createUser = #{createUser,jdbcType=VARCHAR},
createDate = #{createDate,jdbcType=TIMESTAMP},
updateUser = #{updateUser,jdbcType=VARCHAR},
updateDate = #{updateDate,jdbcType=TIMESTAMP},
deleteFlag = #{deleteFlag,jdbcType=INTEGER}
where id = #{id,jdbcType=VARCHAR}
update>
<deleteid="deleteByPrimaryKeys"parameterType="java.util.List">
deletefrom test_user where id in
<foreachcollection="list"index="index"item="id"open="("
separator=","close=")">
#{id}
foreach>
delete>
<selectid="selectListColumnsByExample"parameterType="java.util.Map"
resultType="java.util.Map">
selectid, name, qq, email, phone, createDate, updateDate, deleteFlag
fromtest_user where 1=1
<trim>
<iftest="deleteFlag !=null">
and deleteFlag =#{deleteFlag}
if>
<iftest="id != null andid!=''">
and id = #{id}
if>
<iftest="name != nulland name!=''">
and name likeCONCAT('%','${name}','%')
if>
<iftest="date_s != nulland date_s!=''">
andDATE_FORMAT(updateDate, '%Y-%m-%d') >= DATE_FORMAT(#{date_s}, '%Y-%m-%d')
]]>
if>
<iftest="date_e != nulland date_e!=''">
andDATE_FORMAT(updateDate, '%Y-%m-%d') <= DATE_FORMAT(#{date_e}, '%Y-%m-%d')
]]>
if>
trim>
<choose>
<whentest="orderSql != null and orderSql!=''">
orderby ${orderSql}
when>
<otherwise>
orderby updateDate desc
otherwise>
choose>
select>
mapper>
2.7、添加页面:WebRoot/page/TestUser/add.jsp
<%@ page language="java"import="java.util.*"pageEncoding="UTF-8"%>
<divclass="pageContent">
<formmethod="post"action="testUser/add.do"class="pageForm required-validate"onsubmit="return validateCallback(this,dialogAjaxDone);">
<inputtype="hidden"name="navTabId"value="page_TestUser"/>
<inputtype="hidden"name="callbackType"value="closeCurrent"/>
<inputtype="hidden"name="rel"value="page_TestUser"/>
<inputtype="hidden"name="forwardUrl"value=""/>
<inputtype="hidden"name="confirmMsg"value=""/>
<divclass="pageFormContent"layoutH="56">
<pclass="nowrap">
<label>姓名:label>
<inputname="name"value="${instance.name}"type="text"class="textInputrequired"size="30"/>
p>
<pclass="nowrap">
<label>QQ:label>
<inputname="qq"value="${instance.qq}"type="text"class="textInputrequired"size="30"/>
p>
<pclass="nowrap">
<label>电子邮件:label>
<inputname="email"value="${instance.email}"type="text"class="textInputrequired"size="30"/>
p>
<pclass="nowrap">
<label>联系方式:label>
<inputname="phone"value="${instance.phone}"type="text"class="textInputrequired"size="30"/>
p>
div>
<divclass="formBar">
<ul>
<li><divclass="buttonActive"><divclass="buttonContent"><buttontype="submit">保存button>div>div>li>
<li>
<divclass="button"><divclass="buttonContent"><buttontype="button"class="close">取消button>div>div>
li>
ul>
div>
form>
div >
2.8、添加页面:WebRoot/page/TestUser/edit.jsp
<%@ page language="java"import="java.util.*"pageEncoding="UTF-8"%>
<%@ include file="/resources/_frag/include.inc.jsp"%>
<c:importurl="/resources/_frag/pager/pagerForm.jsp">c:import>
<divclass="pageContent">
<formmethod="post"action="testUser/edit.do"class="pageForm required-validate"onsubmit="return validateCallback(this,dialogAjaxDone);">
<inputtype="hidden"name="navTabId"value="page_TestUser"/>
<inputtype="hidden"name="callbackType"value="closeCurrent"/>
<inputtype="hidden"name="rel"value="page_TestUser"/>
<inputtype="hidden"name="forwardUrl"value=""/>
<inputtype="hidden"name="confirmMsg"value=""/>
<inputtype="hidden"name="id"value="${instance.id}"/>
<divclass="pageFormContent"layoutH="56">
<pclass="nowrap">
<label>ID:label><span>${instance.id}span>
p>
<pclass="nowrap">
<label>姓名:label>
<inputname="name"value="${instance.name}"type="text"class="textInputrequired"size="30"/>
p>
<pclass="nowrap">
<label>QQ:label>
<inputname="qq"value="${instance.qq}"type="text"class="textInputrequired"size="30"/>
p>
<pclass="nowrap">
<label>电子邮件:label>
<inputname="email"value="${instance.email}"type="text"class="textInputrequired"size="30"/>
p>
<pclass="nowrap">
<label>联系方式:label>
<inputname="phone"value="${instance.phone}"type="text"class="textInputrequired"size="30"/>
p>
div>
<divclass="formBar">
<ul>
<li><divclass="buttonActive">
<divclass="buttonContent">
<buttontype="submit">保存button>
div>
div>li>
<li>
<divclass="button">
<divclass="buttonContent">
<buttontype="button"class="close">取消button>
div>
div>
li>
ul>
div>
form>
div>
<%@ page language="java"import="java.util.*"pageEncoding="UTF-8"%>
<%@ include file="/resources/_frag/include.inc.jsp"%>
<divclass="pageContent">
<divclass="pageFormContent"layoutH="56">
<pclass="nowrap">
<label>ID:label>
<span>${instance.id}span>
p>
<pclass="nowrap">
<label>姓名:label>
<span>${instance.name}span>
p>
<pclass="nowrap">
<label>QQ:label>
<span>${instance.qq}span>
p>
<pclass="nowrap">
<label>联系方式:label>
<span>${instance.phone}span>
p>
<pclass="nowrap">
<label>创建人:label>
<span><a>${instance.createUser}a>span>
p>
<pclass="nowrap">
<label>创建时间:label>
<span><a><fmt:formatDatevalue="${instance.createDate}"pattern="yyyy-MM-dd HH:mm:ss"/>a>span>
p>
<pclass="nowrap">
<label>更新人:label>
<span><a>${instance.updateUser}a>span>
p>
<pclass="nowrap">
<label>更新时间:label>
<span><a><fmt:formatDatevalue="${instance.updateDate}"pattern="yyyy-MM-dd HH:mm:ss"/>a>span>
p>
div>
<divclass="formBar">
<ul>
<li>
<divclass="button">
<divclass="buttonContent">
<buttontype="button"class="close">关闭button>
div>
div>
li>
ul>
div>
div>
<%@ page language="java"import="java.util.*"pageEncoding="UTF-8"%>
<%@ include file="/resources/_frag/include.inc.jsp"%>
<c:importurl="/resources/_frag/pager/pagerForm.jsp">c:import>
<divclass="pageHeader">
<formrel="pagerForm"onsubmit="returnnavTabSearch(this);"action="testUser/${deleteFlag==0 ? 'toGCListPage.do' : 'toListPage.do'}"method="post">
<inputtype="hidden"name="conditions"value="name,qq,date_s,date_e"/>
<divclass="searchBar">
<tableclass="searchContent">
<tr>
<td><label>昵称:label><inputname="name"value="${name}"type="text"/>td>
<td><label>QQ:label><inputname="qq"value="${qq}"type="text"/>td>
tr>
<tr>
<td><label>更新开始日期:label><inputname="date_s"type="text"value="${date_s}"class="date"dateFmt="yyyy-MM-ddHH:mm:ss"/>td>
<td><label>更新结束日期:label><inputname="date_e"type="text"value="${date_e}"class="date"dateFmt="yyyy-MM-ddHH:mm:ss"/>td>
tr>
table>
<divclass="subBar">
<ul>
<li><divclass="buttonActive">
<divclass="buttonContent"><buttontype="submit">检索button>div>
div>
li>
ul>
div>
div>
form>
div>
<divclass="pageContent">
<divclass="panelBar">
<ulclass="toolBar">
<li><aclass="add"target="dialog"href="testUser/toAddPage.do"width=900height=400><span>添加span>a>li>
<c:choose>
<c:whentest="${deleteFlag==0}">
<li><aclass="delete"title="确实要删除这些记录吗?"target="selectedTodo"rel="ids"postType="string"href="testUser/deletes.do"><span>批量删除span>a>li>
c:when><c:otherwise>
<li><aclass="delete"title="确实要将这些记录删除至回收站吗?"target="selectedTodo"rel="ids"postType="string"href="testUser/removes.do"><span>批量删除至回收站span>a>li>
c:otherwise>
c:choose>
ul>
div>
<c:setvar="searchRow"value="2"scope="request"/><%--设置当前查询条件行数--%>
<tableclass="table"width="100%"layoutH="${searchRow==0? 75 : 113+25*searchRow}">
<thead>
<tr>
<thwidth="22"><inputtype="checkbox"group="ids"class="checkboxCtrl">th>
<thwidth="50"align="center">序号th>
<thorderField="name"<c:iftest='${param.orderField=="name" }'>class="${param.orderDirection}"c:if>>名称th>
<thorderField="qq"<c:iftest='${param.orderField=="qq" }'>class="${param.orderDirection}"c:if>>QQth>
<thorderField="email"<c:iftest='${param.orderField=="email" }'>class="${param.orderDirection}"c:if>>邮箱th>
<thorderField="phone"<c:iftest='${param.orderField=="phone" }'>class="${param.orderDirection}"c:if>>联系电话th>
<thorderField="updateDate"<c:iftest='${emptyparam.orderField ||param.orderField=="updateDate" }'> class="${param.orderDirection}"c:if>>更新时间th>
<thalign="center">操作th>
tr>
thead>
<tbody>
<c:forEachvar="item"items="${pageList}"varStatus="s">
<trtarget="sid_list"rel="${item.id}">
<td><inputname="ids"value="${item.id}"type="checkbox">td>
<td>${(page.pageNum-1)*page.numPerPage+s.index + 1}td>
<td>${item.name}td>
<td>${item.qq}td>
<td>${item.email}td>
<td>${item.phone}td>
<td><fmt:formatDatevalue="${item.updateDate}"pattern="yyyy-MM-dd HH:mm:ss"/>td>
<tdalign="center">
<c:choose>
<c:whentest="${deleteFlag==0}">
<aclass="fontIcon"href="testUser/recovery.do?id=${item.id}"target="ajaxTodo"title="恢复数据"><spanclass="fa fa-reply fa-lg"style="color:blue"> span>a>
<aclass="btnDel"href="testUser/delete.do?id=${item.id}"target="ajaxTodo"title="确定要删除吗?"><span>span>a>
c:when><c:otherwise>
<aclass="btnView"href="testUser/toViewPage.do?id=${item.id}"target="dialog"title="预览"width=900height=600><span>[详情]span>a>
<aclass="btnEdit"href="testUser/toEditPage.do?id=${item.id}"target="dialog"title="编辑"width=900height=400><span>[修改]span>a>
<aclass="fontIcon"href="testUser/remove.do?id=${item.id}"target="ajaxTodo"title="放入回收站"><spanclass="fa fa-trash-o fa-lg"style="color:red">span>a>
c:otherwise>
c:choose>
td>
tr>
c:forEach>
tbody>
table>
<c:importurl="/resources/_frag/pager/panelBar.jsp">c:import>
div>
<divclass="accordionHeader">
<h2><span>Folderspan>测试管理h2>
div>
<divclass="accordionContent">
<ulclass="treetreeFolder">
<li><ahref="testUser/toListPage.do"target="navTab"rel="page_TestUser">测试用户管理a>li>
ul>
div>