JBMS www. s o f t 8 6 .cn
文档/Doc
JBMS完整案例:客户管理-准备工作
以基于JBMS开发一个客户管理的基本功能来说明如何使用JBMS开发自己的业务功能,开发具体功能前先将相应的框架搭建好;

目录

--step 1(jbms.api 数据载体-实体类)

--step 2(jbms.api配置辅助类-即EModel、EOperate)

--step 3(jbms.api 持久层)

--step 4(jbms.api 业务逻辑层)

--step 5(jbms.api API)

--step 6(jbms.web 配置jbms.api服务)

--step 7(jbms.web 页面及JS)

--step 8(jbms.web 配置模块与菜单)

--step 9(完成 测试)

step 1(jbms.api 数据载体-实体类):

1、api.domain为数据载体的包目录,基于api.domain新建包customer 形成包路径:api.domain.customer ;

2、基于api.domain.customer包新建Customer类,继承BaseEntity类,添加注解:@Entity、@Table(name = "customer_customer")、@ApiModel(value = "客户", description = "")

3、BaseEntity类中定义好ID属性、中文拼音码属性、数据创建、编辑时间属性,业务Bean只需要构建业务属性即可;

4、业务属性定义说明常用类型的定义(需要手动生成GET/SET方法):String、Integer、Long、Lob


//String类型属性
@ApiModelProperty(notes = "客户名称")
@Column(name = "CUSTOMER_NAME", columnDefinition = "VARCHAR(50) DEFAULT '' COMMENT '客户名称'")
private String customerName;

//Integer类型属性,年份因为只有四位用的数据库类型为:SMALLINT 如定义其它Integer可更换成其它对应的INT数据类型
@Column(name = "CREATE_YEAR",columnDefinition="SMALLINT NOT NULL DEFAULT 0 COMMENT '数据产生年份'")
private Integer createYear = DateTimeHelper.getYear();

//Long类型属性
@Column(name = "CREATE_TIMESTAMP",columnDefinition="BIGINT DEFAULT 0 COMMENT '数据创建时间戳'")
private Long createTimestamp = DateTimeHelper.getCurrTimestamp();

//大文本类型属性
@Lob
@Basic(fetch = FetchType.LAZY)
@ApiModelProperty(notes = "参数")
@Column(name = "PARAM",columnDefinition="mediumtext COMMENT '参数'")
private String param;

5、设置数据的拼音码属性,设置拼音码可以构建属性时指定,也可保存数据时手动指定,调用BaseEntity.setPY(String sources)


public void setCustomerName(String customerName) {
	this.customerName = customerName;
	//将客户名称 默认设置为拼音码码
	setPY(customerName);
}

step 2(jbms.api配置辅助类-即EModel、EOperate):

1、EModel配置模块[客户]:M1("M1","客户","/api/customer/"),构建参数:key(模块Key)、modelName(模块名称)、requestMapping(模块请求地址映射);

2、EOperate配置WEB页面操作动作(因当前API服务于jbms.web,配置于EOperate枚举,如开放API给其它服务对象,配置于:EApiOperate枚举),当前分页查询客户数据为:M1_01(EModel.M1,"1",CURD.RETRIEVE,"jbms.web分页查询客户数据","apiAccount");

3、EOperate构造参数:EOperate(EModel model,String key,CURD curd,String operate)

4、EOperate构造参数2:EOperate(EModel model,String key,CURD curd,String operate,String param)

EModel model:EModel即模块,填写页面动作对应的模块;

String key:页面操作Key,约定命名为:初始值为1,同模块内操作增量+1;

CURD curd:页面操作的数据动作,CREATE(插入数据)、UPDATE(编辑数据)、RETRIEVE(查询数据)、DELETE(删除数据)、OTHER(其它);

String operate:操作说明,如:jbms.web分页查询客户数据;

String param:页面操作必须的参数(如无需参数则不填写,用无参数构造方法),多个参数用,连接形成p,p1,p2字符串,请求处理时将首先检查此配置的参数是否满足,如不满足将引发自定义异常:ServiceException.Param404;

5、构建好EOperate中客户管理常用的基础操作,如下;

6、api.cons.EModel,完整代码请下载jbms源码包查看,关键代码如下;


M1("M1","客户","/api/customer/"),

7、api.cons.EOperate,完整代码请下载jbms源码包查看,关键代码如下;


M1_01(EModel.M1,"1",CURD.RETRIEVE,"JBMS分页查询客户数据","apiAccount"),
M1_02(EModel.M1,"2",CURD.CREATE,"JBMS新建客户数据","customerName"),
M1_03(EModel.M1,"3",CURD.UPDATE,"JBMS编辑客户数据","id,customerName"),
M1_04(EModel.M1,"4",CURD.UPDATE,"JBMS客户设置业务状态","ids,stateBuss"),
M1_05(EModel.M1,"5",CURD.DELETE,"JBMS删除客户","ids"),

step 3(jbms.api 持久层):

1、api.mapper持久层的包目录,基于api.mapper新建包customer 形成包路径:api.mapper.customer ;

2、基于api.mapper.customer包新建CustomerMapper接口,继承MapperBase<Customer>接口

step 4(jbms.api 业务逻辑层):

说明:jbms.api中的业务逻辑层与API层通信方法中,约定参数为:JSONObject,返回数据类型为:HttpResult;

1、api.service业务逻辑层接口包目录:基于api.service新建包customer 形成包路径:api.service.customer ;

2、基于api.service.customer包新建ICustomerService接口,继承IBaseService<Customer>

3、api.serviceimpl为业务逻辑层接口实现类的包目录:基于api.serviceimpl新建包customer 形成包路径:api.serviceimpl.customer ;

4、基于api.serviceimpl.customer包新建CustomerServiceImpl类,继承BaseService<Customer> 实现 ICustomerService接口

5、CustomerServiceImpl注入CustomerMapper接口

step 5(jbms.api API):

1、api.api为接口包目录:基于api.api新建包customer 形成包路径:api.api.customer ;

2、基于api.api.customer包新建CustomerAPI接口,继承APIBase,添加注解:@RestController、@RequestMapping("/api/customer/")、@Api(value="客户-API",tags="略")

3、api.api.customer.CustomerAPI 定义常用的API:page、getById、save、edit、del、set_state_buss

page:分页查询接口服务;

getById:根据ID查询数据接口服务;

save:保存数据接口服务;

edit:编辑数据接口服务;

del:删除数据接口服务;

set_state_buss:修改数据业务状态接口服务;

4、完整代码请下载jbms源码包查看,关键代码如下:代码右上角可点击copy按钮复制当前代码段;

api.api.customer.CustomerAPI


@ApiOperation(value="JBMS分页查询客户数据", notes="page/rows如未设置为 page=1,rows=10")
@ApiImplicitParams({
	@ApiImplicitParam(name="apiAccount",value="API用户Code",required=true,paramType="query",dataType="String",defaultValue="api_jbms"),
	@ApiImplicitParam(name="apiToken",value="API 动态令牌",required=true,paramType="query",dataType="String",defaultValue="9B66E5B6-05B0-472C-B955-2B897FE730B9"),
	@ApiImplicitParam(name="timestamp",value="请求时间戳(10位精确到秒)",required=true,paramType="query",dataType="Long",defaultValue="1559192325"),
	@ApiImplicitParam(name="sign",value="请求时间戳(10位精确到秒)",required=true,paramType="query",dataType="Long",defaultValue="4abbcdb5dd6a6cf7c1a353b2f17b5edc"),
	@ApiImplicitParam(name="reqMsg",value="请求携带码原值返回(50位长度)",required=false,paramType="query",dataType="String",defaultValue="myflag"),
	@ApiImplicitParam(name = "page", value = "页码,默认1开始", required = false,paramType="query", dataType = "Integer",defaultValue="1"),
	@ApiImplicitParam(name = "rows", value = "每页加载数量", required = false,paramType="query", dataType = "Integer",defaultValue="10")
})
@ApiResponses(value = {
	@ApiResponse(code = 200, message = "请求处理成功",response = Customer.class)
})
@RequestMapping(value = "page",method = {RequestMethod.GET})
@LogsOperateMark(operate = EOperate.M1_01)
public HttpResult page(HttpServletRequest request,HttpServletResponse response){
	return customerService.pageAdmin(apiHelper.getJsonParam(request));
}

@ApiOperation(value="根据ID查询", notes="")
@ApiImplicitParams({
	@ApiImplicitParam(name="apiAccount",value="API用户Code",required=true,paramType="query",dataType="String",defaultValue="bsoj_judge"),
	@ApiImplicitParam(name="apiToken",value="API 动态令牌",required=true,paramType="query",dataType="String",defaultValue="9B66E5B6-05B0-472C-B955-2B897FE730B9"),
	@ApiImplicitParam(name="timestamp",value="请求时间戳(10位精确到秒)",required=true,paramType="query",dataType="Long",defaultValue="1559192325"),
	@ApiImplicitParam(name="sign",value="请求时间戳(10位精确到秒)",required=true,paramType="query",dataType="Long",defaultValue="4abbcdb5dd6a6cf7c1a353b2f17b5edc"),
	@ApiImplicitParam(name="reqMsg",value="请求携带码原值返回(50位长度)",required=false,paramType="query",dataType="String",defaultValue="myflag"),
	@ApiImplicitParam(name = "id", value = "唯一ID", required = true,paramType="query", dataType = "Long"),
})
@ApiResponses(value = {
		@ApiResponse(code = 200, message = "请求处理成功",response = Customer.class)
})
@RequestMapping(value = "get_by_id",method = {RequestMethod.GET})
public HttpResult getById(HttpServletRequest request,HttpServletResponse response){
	return customerService.getById(apiHelper.getJsonParam(request));
}

@ApiOperation(value="JBMS新建客户数据", notes="")
@ApiImplicitParams({
	@ApiImplicitParam(name="apiAccount",value="API用户Code",required=true,paramType="query",dataType="String",defaultValue="api_jbms"),
	@ApiImplicitParam(name="apiToken",value="API 动态令牌",required=true,paramType="query",dataType="String",defaultValue="9B66E5B6-05B0-472C-B955-2B897FE730B9"),
	@ApiImplicitParam(name="timestamp",value="请求时间戳(10位精确到秒)",required=true,paramType="query",dataType="Long",defaultValue="1559192325"),
	@ApiImplicitParam(name="sign",value="请求时间戳(10位精确到秒)",required=true,paramType="query",dataType="Long",defaultValue="4abbcdb5dd6a6cf7c1a353b2f17b5edc"),
	@ApiImplicitParam(name="reqMsg",value="请求携带码原值返回(50位长度)",required=false,paramType="query",dataType="String",defaultValue="myflag"),
	@ApiImplicitParam(name = "customerName", value = "客户名称", required = true,paramType="query", dataType = "String",defaultValue="测试客户名称"),
	@ApiImplicitParam(name = "customerPhone", value = "客户电话", required = false,paramType="query", dataType = "String",defaultValue="13812349876"),
	@ApiImplicitParam(name = "customerEmail", value = "客户邮箱", required = false,paramType="query", dataType = "String",defaultValue="bsm@soft86.cn"),
	@ApiImplicitParam(name = "contact", value = "联系人", required = false,paramType="query", dataType = "String",defaultValue="逆流"),
	@ApiImplicitParam(name = "contactPhone", value = "联系人手机号码", required = false,paramType="query", dataType = "String",defaultValue="13812349876"),
	@ApiImplicitParam(name = "addrCity", value = "客户对应省-市-区", required = false,paramType="query", dataType = "String",defaultValue="广东省 深圳市 龙岗区"),
	@ApiImplicitParam(name = "addrDesc", value = "客户对应详细地址", required = false,paramType="query", dataType = "String",defaultValue="园山街道大运软件小镇"),
	@ApiImplicitParam(name = "loginAccount", value = "登录账户", required = false,paramType="query", dataType = "String",defaultValue="soft86"),
	@ApiImplicitParam(name = "loginPwd", value = "登录账户密码", required = false,paramType="query", dataType = "String",defaultValue="123456"),
})
@RequestMapping(value = "save",method = {RequestMethod.POST})
@LogsOperateMark(operate = EOperate.M1_02)
public HttpResult save(HttpServletRequest request,HttpServletResponse response){
	return customerService.save(apiHelper.getJsonParam(request));
}

@ApiOperation(value="JBMS编辑客户数据", notes="")
@ApiImplicitParams({
	@ApiImplicitParam(name="apiAccount",value="API用户Code",required=true,paramType="query",dataType="String",defaultValue="api_jbms"),
	@ApiImplicitParam(name="apiToken",value="API 动态令牌",required=true,paramType="query",dataType="String",defaultValue="9B66E5B6-05B0-472C-B955-2B897FE730B9"),
	@ApiImplicitParam(name="timestamp",value="请求时间戳(10位精确到秒)",required=true,paramType="query",dataType="Long",defaultValue="1559192325"),
	@ApiImplicitParam(name="sign",value="请求时间戳(10位精确到秒)",required=true,paramType="query",dataType="Long",defaultValue="4abbcdb5dd6a6cf7c1a353b2f17b5edc"),
	@ApiImplicitParam(name="reqMsg",value="请求携带码原值返回(50位长度)",required=false,paramType="query",dataType="String",defaultValue="myflag"),
	@ApiImplicitParam(name = "id", value = "唯一ID", required = true,paramType="query", dataType = "Long"),
	@ApiImplicitParam(name = "customerName", value = "客户名称", required = true,paramType="query", dataType = "String",defaultValue="测试客户名称"),
	@ApiImplicitParam(name = "customerPhone", value = "客户电话", required = false,paramType="query", dataType = "String",defaultValue="13812349876"),
	@ApiImplicitParam(name = "customerEmail", value = "客户邮箱", required = false,paramType="query", dataType = "String",defaultValue="bsm@soft86.cn"),
	@ApiImplicitParam(name = "contact", value = "联系人", required = false,paramType="query", dataType = "String",defaultValue="逆流"),
	@ApiImplicitParam(name = "contactPhone", value = "联系人手机号码", required = false,paramType="query", dataType = "String",defaultValue="13812349876"),
	@ApiImplicitParam(name = "addrCity", value = "客户对应省-市-区", required = false,paramType="query", dataType = "String",defaultValue="广东省 深圳市 龙岗区"),
	@ApiImplicitParam(name = "addrDesc", value = "客户对应详细地址", required = false,paramType="query", dataType = "String",defaultValue="园山街道大运软件小镇"),
	@ApiImplicitParam(name = "loginAccount", value = "登录账户", required = false,paramType="query", dataType = "String",defaultValue="soft86"),
	@ApiImplicitParam(name = "loginPwd", value = "登录账户密码", required = false,paramType="query", dataType = "String",defaultValue="123456"),
})
@RequestMapping(value = "edit",method = {RequestMethod.POST})
@LogsOperateMark(operate = EOperate.M1_03)
public HttpResult edit(HttpServletRequest request,HttpServletResponse response){
	return customerService.update(apiHelper.getJsonParam(request));
}

@ApiOperation(value="设置业务状态", notes="")
@ApiImplicitParams({
	@ApiImplicitParam(name="apiAccount",value="API用户Code",required=true,paramType="query",dataType="String",defaultValue="bsoj_judge"),
	@ApiImplicitParam(name="apiToken",value="API 动态令牌",required=true,paramType="query",dataType="String",defaultValue="9B66E5B6-05B0-472C-B955-2B897FE730B9"),
	@ApiImplicitParam(name="timestamp",value="请求时间戳(10位精确到秒)",required=true,paramType="query",dataType="Long",defaultValue="1559192325"),
	@ApiImplicitParam(name="sign",value="请求时间戳(10位精确到秒)",required=true,paramType="query",dataType="Long",defaultValue="4abbcdb5dd6a6cf7c1a353b2f17b5edc"),
	@ApiImplicitParam(name="reqMsg",value="请求携带码原值返回(50位长度)",required=false,paramType="query",dataType="String",defaultValue="myflag"),
	@ApiImplicitParam(name = "ids", value = "数据id,多个用,连接而成", required = true,paramType="query", dataType = "String"),
	@ApiImplicitParam(name = "stateBuss", value = "业务数据值", required = true,paramType="query", dataType = "Integer"),
})
@RequestMapping(value = "set_state_buss",method = {RequestMethod.POST})
@LogsOperateMark(operate = EOperate.M1_04)
public HttpResult setStateBuss(HttpServletRequest request,HttpServletResponse response){
	return customerService.setStateBuss(apiHelper.getJsonParam(request));
}

@ApiOperation(value="删除客户", notes="")
@ApiImplicitParams({
	@ApiImplicitParam(name="apiAccount",value="API用户Code",required=true,paramType="query",dataType="String",defaultValue="bsoj_judge"),
	@ApiImplicitParam(name="apiToken",value="API 动态令牌",required=true,paramType="query",dataType="String",defaultValue="9B66E5B6-05B0-472C-B955-2B897FE730B9"),
	@ApiImplicitParam(name="timestamp",value="请求时间戳(10位精确到秒)",required=true,paramType="query",dataType="Long",defaultValue="1559192325"),
	@ApiImplicitParam(name="sign",value="请求时间戳(10位精确到秒)",required=true,paramType="query",dataType="Long",defaultValue="4abbcdb5dd6a6cf7c1a353b2f17b5edc"),
	@ApiImplicitParam(name="reqMsg",value="请求携带码原值返回(50位长度)",required=false,paramType="query",dataType="String",defaultValue="myflag"),
	@ApiImplicitParam(name = "ids", value = "数据id,多个用,连接而成", required = true,paramType="query", dataType = "String"),
})
@RequestMapping(value = "set_state_buss",method = {RequestMethod.POST})
@LogsOperateMark(operate = EOperate.M1_05)
public HttpResult del(HttpServletRequest request,HttpServletResponse response){
	return customerService.del(apiHelper.getJsonParam(request));
}

step 6(jbms.web 配置jbms.api服务):

1、code.api为服务包目录:基于code.api新建包customer 形成包路径:code.api.customer ;

2、基于code.api.customer包新建CustomerAPI类继承APIBase类,添加注解:@RestController、@RequestMapping("/api/customer/")、@Api(value="客户-API",tags="略");

3、code.api.customer.CustomerAPI 定义常用的API:page、getById、save、edit、del、set_state_buss

page:分页查询接口服务;

getById:根据ID查询数据接口服务;

save:保存数据接口服务;

edit:编辑数据接口服务;

del:删除数据接口服务;

set_state_buss:修改数据业务状态接口服务;

4、api_config.js配置接口服务对应code.api.customer.CustomerAPI

api.api.customer.CustomerAPI


@RequestMapping(value = "page",method = {RequestMethod.GET})
public HttpResult page(HttpServletRequest request,HttpServletResponse response) throws CtrException{
	return restTemplate.getForEntity(apiHelper.fromHttpUrl(apiConfig.getCustomerPage(), apiHelper.getRequestParam(request)),
			HttpResult.class).getBody();
}

@RequestMapping(value = "get_by_id",method = {RequestMethod.GET})
public HttpResult getById(HttpServletRequest request,HttpServletResponse response) throws CtrException{
	return restTemplate.getForEntity(apiHelper.fromHttpUrl(apiConfig.getCustomerGetById(), apiHelper.getRequestParam(request)),
			HttpResult.class).getBody();
}

@RequestMapping(value = "save",method = {RequestMethod.POST})
public HttpResult save(HttpServletRequest request,HttpServletResponse response){
	return restTemplate.postForEntity(apiConfig.getCustomerSave(), apiHelper.getRequestParam(request),
			HttpResult.class).getBody();
}

@RequestMapping(value = "edit",method = {RequestMethod.POST})
public HttpResult edit(HttpServletRequest request,HttpServletResponse response){
	return restTemplate.postForEntity(apiConfig.getCustomerEdit(), apiHelper.getRequestParam(request),
			HttpResult.class).getBody();
}

@RequestMapping(value = "del",method = {RequestMethod.POST})
public HttpResult del(HttpServletRequest request,HttpServletResponse response){
	return restTemplate.postForEntity(apiConfig.getCustomerDel(), apiHelper.getRequestParam(request),
			HttpResult.class).getBody();
}

@RequestMapping(value = "set_state_buss",method = {RequestMethod.POST})
public HttpResult setStateBuss(HttpServletRequest request,HttpServletResponse response){
	return restTemplate.postForEntity(apiConfig.getCustomerSetStateBuss(), apiHelper.getRequestParam(request),
			HttpResult.class).getBody();
}

api_config.js配置如下


var http_model = {
	// 对应code.api.customer.CustomerAPI @RequestMapping
	customer :jsCommon.getRootPath() + "api/customer/",
}

var api_config = {
	customer:{
		//分别对应 code.api.customer.CustomerAPI 定义常用的API:page、getById、save、edit、del、set_state_buss
		page:http_model.customer+"page",
		get_by_id:http_model.customer+"get_by_id",
		save:http_model.customer+"save",
		edit:http_model.customer+"edit",
		del:http_model.customer+"del",
		set_state_buss:http_model.customer+"set_state_buss",
	},
}

step 7(jbms.web 页面及JS):

1、新建Js文件夹:src/main/resources/static/js为JS文件根目录,在js目录下新建customer中,形成:js/customer;

2、新建Js文件:从js/temps/复制view.js/add.js/edit.js三个文件到js/customer;

3、新建HTML页面文件夹:src/main/resources/templates 为HTML文件根目录,在templates下新建customer中,形成:templates/customer;

4、新建HTML文件:从templates/temps复制view.html/add.html/edit.html三个文件到templates/customer;

5、修改好templates/customer下view.html/add.html/edit.html与js/customer下的view.js/add.js/edit.js的引用关系;

6、code.ctr为页面控制类包目录:基于code.ctr新建包customer 形成包路径:code.ctr.customer ;

7、基于code.ctr.customer包新建CustomerCtr类,添加注解:@Controller、@RequestMapping("/customer/")

8、code.ctr.customer.CustomerCtr 定义常用的页面:view、add、edit

view:列表页面;

add:新建表单页面;

edit:编辑表单页面;


@RequestMapping("view")
public ModelAndView view(HttpServletRequest request,HttpServletResponse response){
	ModelAndView modelAndView = new ModelAndView("customer/view");
	return modelAndView;
}

@RequestMapping("add")
public ModelAndView add(HttpServletRequest request,HttpServletResponse response){
	ModelAndView modelAndView = new ModelAndView("customer/add");
	return modelAndView;
}

@RequestMapping("edit")
public ModelAndView edit(HttpServletRequest request,HttpServletResponse response) throws CtrException{
	request.setAttribute(ESessionCode.S0000024.code,request.getParameter(EText.id.text));
	
	ModelAndView modelAndView = new ModelAndView("customer/edit");
	return modelAndView;
}

step 8(jbms.web 配置模块与菜单):

参考文档 新建模块与菜单

step 9(完成 测试):

1、登录jbms.web URL:http://localhost:8088/jbms.web/ ;

2、使用超级管理员身份登录(无需配置权限等); 使用其它用户,参考文档:系统用户及权限

3、进入系统后,点击顶部模块栏[客户],加载下左侧菜单,菜单路径:客户管理-客户列表 下右主操作区就打开Tab卡页面;

4、管理页面分为:顶部搜索栏、顶部按钮栏、表格(表格行最右侧为数据行操作区)组成;