SSM+BJUI实现CRUD的报表功能

场景

常见的一种业务就是根据数据库中的单表或者通过关联多表的数据显示在主页面并实现分页、按条件筛选、查看详情

添加记录、编辑记录等。

实现效果

SSM+BJUI实现CRUD的报表功能_第1张图片

代码实现

查询操作

1.编写action

@Controller
@RequestMapping("/sys/cooperativePartnersManageAction")
public class SysCooperativePartnerManageAction  extends BaseAction{
 
 private  SysPartnersService sysPartnersService;
 
 private SysCodeService codeService;
 
 @Autowired
    public void setCodeService(SysCodeService codeService) {
  this.codeService = codeService;
 }
 @Autowired
 public void setSysPartnersService(SysPartnersService sysPartnersService) {
  this.sysPartnersService = sysPartnersService;
 }

注:

RequestMapping后面要在BJUI的页面进行权限的配置时用到,具体参照:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/84232271#commentsedit

然后编写控制跳转后的主页面的action中的方法toList

@RequestMapping(value = "/toList")
 public  ModelAndView toList(Integer pageSize, Integer pageCurrent, String orderField, String orderDirection,
   String partnerName,String companyName) {
  ModelAndView mv = null;
  try {
   PageResult pageResult = PageUtil.pageSet(this.getClass(), pageSize, pageCurrent, orderField, orderDirection);
   pageResult.getParam().put("status", "0");
   //插入模糊搜索数据
   if (partnerName != null && !"".equals(partnerName)) {
    pageResult.getParam().put("partnerName", partnerName);
    pageResult.getExt().put("partnerName", partnerName);
   }
   if (companyName != null && !"".equals(companyName)) {
    pageResult.getParam().put("companyName", companyName);
    pageResult.getExt().put("companyName", companyName);
   }
   
   pageResult.setOrderField("sp.RecordTime");
   pageResult.setOrderDirection("DESC");
   pageResult = this.sysPartnersService.getPartnerListPageResult(pageResult);
   mv = new ModelAndView();
   mv.addObject(ModelAndViewConstants.PAGE_RESULT, pageResult);
   mv.setViewName(ModelAndViewConstants.PARTNER_MAIN_VIEW);
  } catch (Exception e) {
   mv = new ModelAndView(ModelAndViewConstants.ERROR_VIEW);
   LogService.getInstance(this).debug(e);
  }
  return mv;
 
 }

注:

①方法参数中的 String partnerName,String companyName是前端页面在实现模糊查询时传过来的参数

SSM+BJUI实现CRUD的报表功能_第2张图片

②PageResult是一个封装了页面返回数据(页面数据、分页相关、查询时排序参数等)

public class PageResult implements Serializable {
 
 private Integer pageCurrent = 1;           //当前页索引
 private Integer pageSize = 10;           //每页记录数
 private Map param = new HashMap();  //传入的参数,param和where只用一个
 private String where;             //where条件字符串,where和param只用一个
 private String orderField;            //排序字段
 private String orderDirection = "ASC";          //排序方向,升序or降序
 private Integer total;            //总记录数
 private List list = new ArrayList();        //页面数据
 private Map ext = new HashMap();

省略get、set方法。

③status设置为0,表示数据是正常数据,未被修改过。

④然后将前端传来的模糊查询的参数赋值。

⑤pageResult.setOrderField("sp.RecordTime");
    pageResult.setOrderDirection("DESC");
是设置查询后的数据的排序字段以及排序方式,其中sp要与mapper文件中执行select语句时的别名一致。

⑥pageResult = this.sysPartnersService.getPartnerListPageResult(pageResult);

然后执行service层的查询数据的方法,参数以及返回值类型都是pageResult 。

⑦最后将查询到的数据传递到指定的页面:

   mv.addObject(ModelAndViewConstants.PAGE_RESULT, pageResult);
   mv.setViewName(ModelAndViewConstants.PARTNER_MAIN_VIEW);

2.编写service

 

public interface SysPartnersService extends BaseService {
 /**
  * 功能说明:通过PageResult获取分页数据
  * 修改说明:
  * @author badao
  * @date 2018/11/13 周二: 9:20:55.03
  * @param pageResult 分页查询对象,包含查询条件
  * @return 返回分页查询对象,包含页面数据
  */
 public PageResult getPartnerListPageResult(PageResult pageResult);

3.编写serviceImpl

@Service("sysPartnersService")
public class SysPartnersServiceImpl extends BaseServiceImpl implements SysPartnersService {
 private SysPartnersDao dao;

 @Autowired
 public void setDao(SysPartnersDao dao) {
  super.setDao(dao);
  this.dao = dao;
 }

 @Override
 public PageResult getPartnerListPageResult(PageResult pageResult) {
  // TODO Auto-generated method stub
  return this.dao.getPartnerListPageResult(pageResult);
 }

4.编写dao

 

public interface SysPartnersDao extends BaseDao{
 /**
  * 功能说明:通过PageResult获取分页数据
  * 修改说明:
  * @author badao
  * @date 2018/11/13 周二: 9:55:54.57
  * @param pageResult 分页查询对象,包含查询条件
  * @return 返回分页查询对象,包含页面数据
  */
  public PageResult getPartnerListPageResult(PageResult pageResult);

5.编写daoImpl

 

@Repository("sysPartnersDao")
public class SysPartnersDaoImpl extends BaseDaoImpl implements SysPartnersDao {
 /**
  * 功能说明:获取列表分页数据
  * 修改说明:
  * @author badao
  * @date 2018/11/13 周二:10:55:37.38
  * @param params 查询参数
  * @return 返回符合条件的记录集合
  */
 public List getPartnersListByParam(Map params) {
  String stmtId = this.getNameSpace() + MapperIdConstants._GETPARTNERSLISTBYPARAM;
  return this.getSqlSession().selectList(stmtId, params);
 }

6.编写mapper层

用代码生成工具生成的mapper层:




     
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
 
  Id, PartnerNum, SignKey, PartnerName, CompanyName, ContactName, ContactMobile, ContactAddress, Extension, ContactFixed, ContactCardNum, Email, Province, City, District, ContractStatus, ContractStatusName, TestContractTime, FormalContractTime, VipRestRoomPrice, CipRestRoomPrice, PassPrice, CurrentAdvanceMoney, QqNum, MicroBlog, ModifyUserId, ModifyUserName, RecordTime, Status, Remark
 

 
 

 

 
 

 
 

 
 

 
 

 
 
 
  
 
  insert into sys_partners ( PartnerNum,  SignKey,  PartnerName,  CompanyName,  ContactName,  ContactMobile,  ContactAddress,  Extension,  ContactFixed,  ContactCardNum,  Email,  Province,  City,  District,  ContractStatus,  ContractStatusName,  TestContractTime,  FormalContractTime,  VipRestRoomPrice,  CipRestRoomPrice,  PassPrice,  CurrentAdvanceMoney,  QqNum,  MicroBlog,  ModifyUserId,  ModifyUserName,  RecordTime,  Status,  Remark)
  values (#{partnerNum,jdbcType=VARCHAR}, #{signKey,jdbcType=VARCHAR}, #{partnerName,jdbcType=VARCHAR}, #{companyName,jdbcType=VARCHAR}, #{contactName,jdbcType=VARCHAR}, #{contactMobile,jdbcType=VARCHAR}, #{contactAddress,jdbcType=VARCHAR}, #{extension,jdbcType=VARCHAR}, #{contactFixed,jdbcType=VARCHAR}, #{contactCardNum,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, #{district,jdbcType=VARCHAR}, #{contractStatus,jdbcType=INTEGER}, #{contractStatusName,jdbcType=VARCHAR}, #{testContractTime,jdbcType=TIMESTAMP}, #{formalContractTime,jdbcType=TIMESTAMP}, #{vipRestRoomPrice,jdbcType=DECIMAL}, #{cipRestRoomPrice,jdbcType=DECIMAL}, #{passPrice,jdbcType=DECIMAL}, #{currentAdvanceMoney,jdbcType=DECIMAL}, #{qqNum,jdbcType=VARCHAR}, #{microBlog,jdbcType=VARCHAR}, #{modifyUserId,jdbcType=INTEGER}, #{modifyUserName,jdbcType=VARCHAR}, #{recordTime,jdbcType=TIMESTAMP}, #{status,jdbcType=CHAR}, #{remark,jdbcType=VARCHAR})
 

 
 
  insert into sys_partners ( PartnerNum,  SignKey,  PartnerName,  CompanyName,  ContactName,  ContactMobile,  ContactAddress,  Extension,  ContactFixed,  ContactCardNum,  Email,  Province,  City,  District,  ContractStatus,  ContractStatusName,  TestContractTime,  FormalContractTime,  VipRestRoomPrice,  CipRestRoomPrice,  PassPrice,  CurrentAdvanceMoney,  QqNum,  MicroBlog,  ModifyUserId,  ModifyUserName,  RecordTime,  Status,  Remark)
  
   select #{item.partnerNum,jdbcType=VARCHAR}, #{item.signKey,jdbcType=VARCHAR}, #{item.partnerName,jdbcType=VARCHAR}, #{item.companyName,jdbcType=VARCHAR}, #{item.contactName,jdbcType=VARCHAR}, #{item.contactMobile,jdbcType=VARCHAR}, #{item.contactAddress,jdbcType=VARCHAR}, #{item.extension,jdbcType=VARCHAR}, #{item.contactFixed,jdbcType=VARCHAR}, #{item.contactCardNum,jdbcType=VARCHAR}, #{item.email,jdbcType=VARCHAR}, #{item.province,jdbcType=VARCHAR}, #{item.city,jdbcType=VARCHAR}, #{item.district,jdbcType=VARCHAR}, #{item.contractStatus,jdbcType=INTEGER}, #{item.contractStatusName,jdbcType=VARCHAR}, #{item.testContractTime,jdbcType=TIMESTAMP}, #{item.formalContractTime,jdbcType=TIMESTAMP}, #{item.vipRestRoomPrice,jdbcType=DECIMAL}, #{item.cipRestRoomPrice,jdbcType=DECIMAL}, #{item.passPrice,jdbcType=DECIMAL}, #{item.currentAdvanceMoney,jdbcType=DECIMAL}, #{item.qqNum,jdbcType=VARCHAR}, #{item.microBlog,jdbcType=VARCHAR}, #{item.modifyUserId,jdbcType=INTEGER}, #{item.modifyUserName,jdbcType=VARCHAR}, #{item.recordTime,jdbcType=TIMESTAMP}, #{item.status,jdbcType=CHAR}, #{item.remark,jdbcType=VARCHAR}
  
 
 
 
 
  update sys_partners
  
   PartnerNum = #{partnerNum,jdbcType=VARCHAR},
   SignKey = #{signKey,jdbcType=VARCHAR},
   PartnerName = #{partnerName,jdbcType=VARCHAR},
   CompanyName = #{companyName,jdbcType=VARCHAR},
   ContactName = #{contactName,jdbcType=VARCHAR},
   ContactMobile = #{contactMobile,jdbcType=VARCHAR},
   ContactAddress = #{contactAddress,jdbcType=VARCHAR},
   Extension = #{extension,jdbcType=VARCHAR},
   ContactFixed = #{contactFixed,jdbcType=VARCHAR},
   ContactCardNum = #{contactCardNum,jdbcType=VARCHAR},
   Email = #{email,jdbcType=VARCHAR},
   Province = #{province,jdbcType=VARCHAR},
   City = #{city,jdbcType=VARCHAR},
   District = #{district,jdbcType=VARCHAR},
   ContractStatus = #{contractStatus,jdbcType=INTEGER},
   ContractStatusName = #{contractStatusName,jdbcType=VARCHAR},
   TestContractTime = #{testContractTime,jdbcType=TIMESTAMP},
   FormalContractTime = #{formalContractTime,jdbcType=TIMESTAMP},
   VipRestRoomPrice = #{vipRestRoomPrice,jdbcType=DECIMAL},
   CipRestRoomPrice = #{cipRestRoomPrice,jdbcType=DECIMAL},
   PassPrice = #{passPrice,jdbcType=DECIMAL},
   CurrentAdvanceMoney = #{currentAdvanceMoney,jdbcType=DECIMAL},
   QqNum = #{qqNum,jdbcType=VARCHAR},
   MicroBlog = #{microBlog,jdbcType=VARCHAR},
   ModifyUserId = #{modifyUserId,jdbcType=INTEGER},
   ModifyUserName = #{modifyUserName,jdbcType=VARCHAR},
   RecordTime = #{recordTime,jdbcType=TIMESTAMP},
   Status = #{status,jdbcType=CHAR},
   Remark = #{remark,jdbcType=VARCHAR},
  
  
   Id = #{id,jdbcType=INTEGER}
  
 
 
  
 
  
   update sys_partners
   
    PartnerNum = #{item.partnerNum,jdbcType=VARCHAR},
    SignKey = #{item.signKey,jdbcType=VARCHAR},
    PartnerName = #{item.partnerName,jdbcType=VARCHAR},
    CompanyName = #{item.companyName,jdbcType=VARCHAR},
    ContactName = #{item.contactName,jdbcType=VARCHAR},
    ContactMobile = #{item.contactMobile,jdbcType=VARCHAR},
    ContactAddress = #{item.contactAddress,jdbcType=VARCHAR},
    Extension = #{item.extension,jdbcType=VARCHAR},
    ContactFixed = #{item.contactFixed,jdbcType=VARCHAR},
    ContactCardNum = #{item.contactCardNum,jdbcType=VARCHAR},
    Email = #{item.email,jdbcType=VARCHAR},
    Province = #{item.province,jdbcType=VARCHAR},
    City = #{item.city,jdbcType=VARCHAR},
    District = #{item.district,jdbcType=VARCHAR},
    ContractStatus = #{item.contractStatus,jdbcType=INTEGER},
    ContractStatusName = #{item.contractStatusName,jdbcType=VARCHAR},
    TestContractTime = #{item.testContractTime,jdbcType=TIMESTAMP},
    FormalContractTime = #{item.formalContractTime,jdbcType=TIMESTAMP},
    VipRestRoomPrice = #{item.vipRestRoomPrice,jdbcType=DECIMAL},
    CipRestRoomPrice = #{item.cipRestRoomPrice,jdbcType=DECIMAL},
    PassPrice = #{item.passPrice,jdbcType=DECIMAL},
    CurrentAdvanceMoney = #{item.currentAdvanceMoney,jdbcType=DECIMAL},
    QqNum = #{item.qqNum,jdbcType=VARCHAR},
    MicroBlog = #{item.microBlog,jdbcType=VARCHAR},
    ModifyUserId = #{item.modifyUserId,jdbcType=INTEGER},
    ModifyUserName = #{item.modifyUserName,jdbcType=VARCHAR},
    RecordTime = #{item.recordTime,jdbcType=TIMESTAMP},
    Status = #{item.status,jdbcType=CHAR},
    Remark = #{item.remark,jdbcType=VARCHAR},
   
   
    Id = #{item.id,jdbcType=INTEGER}
   
  
 
 
  
 
  delete from sys_partners where Id = #{id, jdbcType=INTEGER}
 

 
  delete from sys_partners where Id = #{id}
 
 
 
 
  delete from sys_partners
  
   Id= #{id}
    and PartnerNum = #{partnerNum}
    and SignKey = #{signKey}
    and PartnerName = #{partnerName}
    and CompanyName = #{companyName}
    and ContactName = #{contactName}
    and ContactMobile = #{contactMobile}
    and ContactAddress = #{contactAddress}
    and Extension = #{extension}
    and ContactFixed = #{contactFixed}
    and ContactCardNum = #{contactCardNum}
    and Email = #{email}
    and Province = #{province}
   and City= #{city}
    and District = #{district}
    and ContractStatus = #{contractStatus}
    and ContractStatusName = #{contractStatusName}
    and TestContractTime = #{testContractTime}
    and FormalContractTime = #{formalContractTime}
    and VipRestRoomPrice = #{vipRestRoomPrice}
    and CipRestRoomPrice = #{cipRestRoomPrice}
    and PassPrice = #{passPrice}
    and CurrentAdvanceMoney = #{currentAdvanceMoney}
    and QqNum = #{qqNum}
    and MicroBlog = #{microBlog}
    and ModifyUserId = #{modifyUserId}
    and ModifyUserName = #{modifyUserName}
    and RecordTime = #{recordTime}
    and Status = #{status}
    and Remark = #{remark}
  
 
 
 
 
  delete from sys_partners where Id in
  
   
    #{pk}
   
  
 

 
 
  delete from sys_partners where 1=1 and ${where}
 
 
 
 
  truncate table sys_partners
 
 




自己编写的mapper层




    
 
 
 
 
 
 
 
 
 

7.编写model层

代码生成工具生成:

public class SysPartners implements java.io.Serializable{
 private Integer id;
 private String partnerNum;
 private String signKey;
 private String partnerName;
 private String companyName;
 private String contactName;
 private String contactMobile;
 private String contactAddress;
 private String extension;
 private String contactFixed;
 private String contactCardNum;
 private String email;
 private String province;
 private String city;
 private String district;
 private Integer contractStatus;
 private String contractStatusName;
 private Date testContractTime;
 private Date formalContractTime;
 private BigDecimal vipRestRoomPrice;
 private BigDecimal cipRestRoomPrice;
 private BigDecimal passPrice;
 private BigDecimal currentAdvanceMoney;
 private String qqNum;
 private String microBlog;
 private Integer modifyUserId;
 private String modifyUserName;
 private Date recordTime;
 private String status;
 private String remark;

省略set、get方法

自己编写的model:

public class SysPartnersExt  extends SysPartners{
 private String contractStatusNameInCode;

 public String getContractStatusNameInCode() {
  return contractStatusNameInCode;
 }

 public void setContractStatusNameInCode(String contractStatusNameInCode) {
  this.contractStatusNameInCode = contractStatusNameInCode;
 }
}

8.编写jsp页面

列表展示的主页面:


 
                                       
                           添加                           编辑                  <%--         删除        --%>            
     
  
        
     
                
       
                                                                                                                                                                                                                                                                  
状态合作方身份编号合作方名称合作方公司名称合作方联系人名称合作方联系人电话当前签约状态修改人编号修改人名称查看详情
${u.partnerNum}${u.partnerName}${u.companyName}${u.contactName}${u.contactMobile}${u.contractStatusName}${u.modifyUserId}${u.modifyUserName}                 


 配置BJUI

要想在BJUI的页面上载左边点击菜单栏,右边出现此页面还要进行权限配置

具体参照:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/84232271

实现添加以及编辑

SSM+BJUI实现CRUD的报表功能_第3张图片

SSM+BJUI实现CRUD的报表功能_第4张图片

关于BJUI的校验,参照:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/84065856

关于编辑以及添加功能的实现大同小异,具体参照:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/84098171

完整代码

action:

 

@Controller
@RequestMapping("/sys/cooperativePartnersManageAction")
public class SysCooperativePartnerManageAction  extends BaseAction{
 
 private  SysPartnersService sysPartnersService;
 
 private SysCodeService codeService;
 
 @Autowired
    public void setCodeService(SysCodeService codeService) {
  this.codeService = codeService;
 }
 @Autowired
 public void setSysPartnersService(SysPartnersService sysPartnersService) {
  this.sysPartnersService = sysPartnersService;
 }
 /**
  *
  * 功能说明:分页展示
  * 修改说明:
  * @author badao
  * @date 2018/11/13 周二: 9:03:48.49
  * @param pageSize 每页记录数
  * @param pageCurrent 当前页索引
  * @param orderField 排序字段
  * @param orderDirection 排序方向 
  * @return
  */
 @RequestMapping(value = "/toList")
 public  ModelAndView toList(Integer pageSize, Integer pageCurrent, String orderField, String orderDirection,
   String partnerName,String companyName) {
  ModelAndView mv = null;
  try {
   PageResult pageResult = PageUtil.pageSet(this.getClass(), pageSize, pageCurrent, orderField, orderDirection);
   pageResult.getParam().put("status", "0");
   //插入模糊搜索数据
   if (partnerName != null && !"".equals(partnerName)) {
    pageResult.getParam().put("partnerName", partnerName);
    pageResult.getExt().put("partnerName", partnerName);
   }
   if (companyName != null && !"".equals(companyName)) {
    pageResult.getParam().put("companyName", companyName);
    pageResult.getExt().put("companyName", companyName);
   }
   
   pageResult.setOrderField("sp.RecordTime");
   pageResult.setOrderDirection("DESC");
   pageResult = this.sysPartnersService.getPartnerListPageResult(pageResult);
   mv = new ModelAndView();
   mv.addObject(ModelAndViewConstants.PAGE_RESULT, pageResult);
   mv.setViewName(ModelAndViewConstants.PARTNER_MAIN_VIEW);
  } catch (Exception e) {
   mv = new ModelAndView(ModelAndViewConstants.ERROR_VIEW);
   LogService.getInstance(this).debug(e);
  }
  return mv;
 
 }
 /**
  * 功能说明:进入详情显示界面
  * 修改说明:
  * @author badao
  * @date 2018/11/13 周二:13:15:21.56
  * @param pageSize 每页记录数
  * @param pageCurrent 当前页索引
  * @param orderField 排序字段
  * @param orderDirection 排序方向
  * @param paramCompanyName 参数字段:客户名称
  * @param paramRemark 参数字段:备注
  * @return
  */
 @RequestMapping(value="/toDetails")
 public ModelAndView toDetails(Integer id) {
  ModelAndView mv = null;
  try {
   SysPartnersExt partner=this.sysPartnersService.getDetailsByPrimaryKey(id);
   partner.setStatus("0");
   mv = new ModelAndView();
   mv.addObject(ModelAndViewConstants.PARTMER, partner);
   mv.setViewName(ModelAndViewConstants.PARTNER_DETAILS_VIEW);
   LogService.getInstance(this).debug("获取分页数据成功:"+ModelAndViewConstants.PARTNER_DETAILS_VIEW);
  }
  catch(Exception ex) {
   LogService.getInstance(this).error("获取分页数据失败:" + ex.getMessage(), ex);
   mv = new ModelAndView(ModelAndViewConstants.ERROR_VIEW);
  }
  return mv;
 }
 
 /**
  * 功能说明:进入添加界面操作
  * 修改说明:
  * @author badao
  * @date 2018/11/13 周二:16:32:49.00
  * @return
  */
 @RequestMapping(value="/toAdd")
 public ModelAndView toAdd(){
  ModelAndView mv = null;
  try {
   //查询签约状态
   Map param = new HashMap();
   param.put("status", "0");
   param.put("codeType", "contractStatus");
   List contractStatus = codeService.getByParam(param);
   mv = new ModelAndView();
   //传递签约状态
   mv.addObject("contractStatus", contractStatus);
   //传递当前的操作类型的标识,左边是op常量参数,表示操作类型,右边是add常量参数,表示是添加操作
   mv.addObject(ModelAndViewConstants.OPERATION_KEY,ModelAndViewConstants.OPERATION_VALUE_ADD);
   //传递到共用页面的标题参数,左边是title常量参数,右边是要显示的标题的内容
   mv.addObject(ModelAndViewConstants.TITLE_KEY, "添加合作商户信息");
   //跳转的具体的页面
   mv.setViewName(ModelAndViewConstants.PARTNER_EDIT_VIEW);
   LogService.getInstance(this).error("进入添加功能成功:" +ModelAndViewConstants.PARTNER_EDIT_VIEW);
  }
  catch(Exception ex) {
   LogService.getInstance(this).error("进入添加失败:" + ex.getMessage(), ex);
   mv = new ModelAndView("redirect:/error.jsp");
  }
  return mv;
 }
 
 /**
  * 功能说明:执行保存操作
  * 修改说明:
  * @author badao
  * @date 2018/11/14 周三:10:40:41.65
  * @param entity 客户信息实体
  * @paramopop=add为添加操作,op=edit为编辑操作
  * @return 返回json对象
  */
 @ResponseBody
 @RequestMapping(value="/doSave")
 public Map doSave(SysPartners entity, String op) {
  Map jsonResult = null;
  try {
   //与配置权限管理中相对应,实现添加或编辑完实时更新
   String tabid = tabid(ModelAndViewConstants.PARTNER_SYS_ID);
   //如果是测试签约
   if(entity.getContractStatus()==0) {
    entity.setTestContractTime(new Date());
    entity.setContractStatusName("测试签约");
   }
   //如果是正式签约
   if(entity.getContractStatus()==1) {
    entity.setFormalContractTime(new Date());
    entity.setContractStatusName("正式签约");
   }
   entity.setRecordTime(new Date());
   //获得当前用户的id和name,加入客户对象中
   ShiroUser currentUser = (ShiroUser)SecurityUtils.getSubject().getPrincipal();
   entity.setModifyUserId(currentUser.getUserId());
   entity.setModifyUserName(currentUser.getAccount());
   //如果op标志参数为空,或者为add 那么就执行添加操作
   if (null == op || ModelAndViewConstants.OPERATION_VALUE_ADD.equals(op)) {
    //此字段表示数据未被更改
    entity.setStatus("0");
    //执行插入数据操作,方法是有代码生成工具自动生成
    int count = this.sysPartnersService.insert(entity);
    if (count > 0) {
     LogService.getInstance(this).debug("添加信息成功!");
    }
   }
   else {
    //如果不是,则就是编辑后的保存操作
    //获取现存数据,也是通过代码生成工具生成的方法
    SysPartners currentSysPartner = this.sysPartnersService.getByPrimaryKey(entity);
    int count = this.sysPartnersService.updateByPrimaryKey(entity);
    if (count > 0) {
     LogService.getInstance(this).debug("编辑信息成功!");
    }
   }
   Integer statusCode = 200;
   String msg = "保存成功";
   jsonResult = JsonResult.jsonReturn(statusCode, msg, tabid);
  }
  catch(Exception ex) {
   LogService.getInstance(this).error("保存信息失败:" + ex.getMessage(), ex);
   String msg =  "保存信息失败:" + ex.getMessage();
   jsonResult = JsonResult.jsonReturnErr(msg);
  }
  return jsonResult;
 }
 /**
  * 功能说明:进入编辑界面
  * 修改说明:
  * @author badao
  * @date 2018/11/13 周二:16:32:49.00
  * @param id 用户id,主键值
  * @return
  */
 @RequestMapping(value="/toEdit")
 public ModelAndView toEdit(Integer id) {
  ModelAndView mv = null;
  try {
   //根据ID先查询要编辑的数据
   SysPartners partner = this.sysPartnersService.getByPrimaryKey(id);
   //获取签约状态,此处是通过关联码表来实现
   Map param = new HashMap();
   //0 表示正常数据
   param.put("status", "0");
   param.put("codeType", "contractStatus");
   //根据参数将相关码表内容查询出来
   List contractStatus = codeService.getByParam(param);
   mv = new ModelAndView();
   //传递签约状态
   mv.addObject("contractStatus", contractStatus);
   //传递操作类型,这里是编辑操作
   mv.addObject(ModelAndViewConstants.OPERATION_KEY,ModelAndViewConstants.OPERATION_VALUE_EDIT);
   //jsp页面要显示的标题title
   mv.addObject(ModelAndViewConstants.TITLE_KEY, "修改信息");
   //将查询到的实体Model类传递
   mv.addObject(ModelAndViewConstants.PARTMER, partner);
   //跳转到编辑界面
   mv.setViewName(ModelAndViewConstants.PARTNER_EDIT_VIEW);
  }
  catch(Exception ex) {
   LogService.getInstance(this).error("进入编辑失败:" + ex.getMessage(), ex);
   mv = new ModelAndView(ModelAndViewConstants.ERROR_VIEW);
  }
  return mv;
 }


}

service

public interface SysPartnersService extends BaseService {
 /**
  * 功能说明:通过PageResult获取分页数据
  * 修改说明:
  * @author badao
  * @date 2018/11/13 周二: 9:20:55.03
  * @param pageResult 分页查询对象,包含查询条件
  * @return 返回分页查询对象,包含页面数据
  */
 public PageResult getPartnerListPageResult(PageResult pageResult);
 /**
  * 功能说明:通过id获取合作伙伴详情数据
  * 修改说明:
  * @author badao
  * @date 2018/11/13 周二: 9:20:55.03
  *
  *
  */
 public SysPartnersExt getDetailsByPrimaryKey(Integer id);


 

serviceImpl

@Service("sysPartnersService")
public class SysPartnersServiceImpl extends BaseServiceImpl implements SysPartnersService {
 private SysPartnersDao dao;

 @Autowired
 public void setDao(SysPartnersDao dao) {
  super.setDao(dao);
  this.dao = dao;
 }

 @Override
 public PageResult getPartnerListPageResult(PageResult pageResult) {
  // TODO Auto-generated method stub
  return this.dao.getPartnerListPageResult(pageResult);
 }
 @Override
 public SysPartnersExt getDetailsByPrimaryKey(Integer id) {
  // TODO Auto-generated method stub
  return dao.getDetailsByPrimaryKey(id);
 }
}

dao

public interface SysPartnersDao extends BaseDao{
 /**
  * 功能说明:通过PageResult获取分页数据
  * 修改说明:
  * @author badao
  * @date 2018/11/13 周二: 9:55:54.57
  * @param pageResult 分页查询对象,包含查询条件
  * @return 返回分页查询对象,包含页面数据
  */
  public PageResult getPartnerListPageResult(PageResult pageResult);
 
  public SysPartnersExt getDetailsByPrimaryKey(Integer id);

}

 

daoImpl

@Repository("sysPartnersDao")
public class SysPartnersDaoImpl extends BaseDaoImpl implements SysPartnersDao {
 /**
  * 功能说明:获取分页数据
  * 修改说明:
  * @author badao
  * @date 2018/11/13 周二:10:55:37.38
  * @param params 查询参数
  * @return 返回符合条件的公司记录集合
  */
 public List getPartnersListByParam(Map params) {
  String stmtId = this.getNameSpace() + MapperIdConstants._GETPARTNERSLISTBYPARAM;
  return this.getSqlSession().selectList(stmtId, params);
 }

 /**
  * 功能说明:获取分页数据的总页数
  * 修改说明:
  * @author baado
  * @date 2018/11/13 周二:10:55:37.38
  * @param params 查询参数
  * @return 返回符合条件的总页数
  */
 public Integer countOfPartnersListByParam(Map params) {
  String stmtId = this.getNameSpace() + MapperIdConstants._COUNTOFPARTNERSLISTBYPARAM;
  return this.getSqlSession().selectOne(stmtId, params);
 }
 
 
 /**
  * 功能说明:通过PageResult获取公司分页数据
  * 修改说明:
  * @author badao
  * @date 2018/11/13 周二:10:00:43.03
  * @param pageResult 分页查询对象,包含查询条件
  * @return 返回分页查询对象,包含页面数据
  */
 @Override
 public PageResult getPartnerListPageResult(PageResult pageResult) {
  pageResult.getParam().put("offset", pageResult.getPageSize() * (pageResult.getPageCurrent() - 1));
  pageResult.getParam().put("limit", pageResult.getPageSize());
  if (!"".equals(pageResult.getOrderField())) { pageResult.getParam().put("orderColumn", pageResult.getOrderField()); }
  pageResult.getParam().put("orderTurn", pageResult.getOrderDirection());
  List data = this.getPartnersListByParam(pageResult.getParam());
  pageResult.setList(data);
  int totalSize = this.countOfPartnersListByParam(pageResult.getParam());
  pageResult.setTotal(totalSize);
  return pageResult;
 }

 @Override
 public SysPartnersExt getDetailsByPrimaryKey(Integer id) {
  // TODO Auto-generated method stub
  String stmtId = this.getNameSpace() + MapperIdConstants._GETDETAILSBYPRIMARYKEY;
  return this.getSqlSession().selectOne(stmtId, id);
  
 }

}

Mapper

 


    
 
 
 
 
 
 
 
 
 
 

Model

public class SysPartners implements java.io.Serializable{
 private Integer id;
 private String partnerNum;
 private String signKey;
 private String partnerName;
 private String companyName;
 private String contactName;
 private String contactMobile;
 private String contactAddress;
 private String extension;
 private String contactFixed;
 private String contactCardNum;
 private String email;
 private String province;
 private String city;
 private String district;
 private Integer contractStatus;
 private String contractStatusName;
 private Date testContractTime;
 private Date formalContractTime;
 private BigDecimal vipRestRoomPrice;
 private BigDecimal cipRestRoomPrice;
 private BigDecimal passPrice;
 private BigDecimal currentAdvanceMoney;
 private String qqNum;
 private String microBlog;
 private Integer modifyUserId;
 private String modifyUserName;
 private Date recordTime;
 private String status;
 private String remark;


public class SysPartnersExt  extends SysPartners{
 private String contractStatusNameInCode;



 public String getContractStatusNameInCode() {
  return contractStatusNameInCode;
 }

 public void setContractStatusNameInCode(String contractStatusNameInCode) {
  this.contractStatusNameInCode = contractStatusNameInCode;
 }


}

JSP

主页面:


 
                                       
                           添加                           编辑                  <%--         删除        --%>            
     
  
        
     
                
       
                                                                                                                                                                                                                                                                  
状态合作方身份编号合作方名称合作方公司名称合作方联系人名称合作方联系人电话当前签约状态修改人编号修改人名称查看详情
${u.partnerNum}${u.partnerName}${u.companyName}${u.contactName}${u.contactMobile}${u.contractStatusName}${u.modifyUserId}${u.modifyUserName}                 

详情页面:

                                                                                                                                                                                                                                   
     
      合作方名称:${partner.partnerName}      
    
合作方身份编号:合作方名称:合作方公司名称:合作方联系人名称:合作方联系人电话:联系人地址:
${partner.partnerNum}${partner.partnerName}${partner.companyName}${partner.contactName}${partner.contactMobile}${partner.contactAddress}
记录时间:

添加编辑共享页面:

 
                                                                                                                                                                                                                                                                         

${title}

                                         
                    
                                         
     证件号码:                              
                                    
                                   
                                   
                                    
                                   
                   
 

 

你可能感兴趣的:(BJUI,SSM)