<script type="text/javascript" src="../plugins/angularjs/angular.min.js"> </script>
<script src="../plugins/angularjs/pagination.js"></script>
<link rel="stylesheet" href="../plugins/angularjs/pagination.css">
<script type="text/javascript" src="../js/base_pagination.js"> </script>
<script type="text/javascript" src="../js/service/specificationService.js">
</script>
<script type="text/javascript" src="../js/controller/baseController.js"></script>
<script type="text/javascript" src="../js/controller/specificationController.js">
</script>
<!-- 分页 -->
<tm-pagination conf="paginationConf"></tm-pagination>
<body class="hold-transition skin-red sidebar-mini"
ng-app="pinyougou" ng-controller="specificationController" >
<tr ng-repeat="entity in list">
<td><input type="checkbox" ></td>
<td>{{entity.id}}</td>
<td>{{entity.specName}}</td>
<td class="text-center">
<button type="button" class="btn bg-olive btn-xs" data-toggle="modal"
data-target="#editModal">修改</button>
</td>
</tr>
//新增选项行
$scope.addTableRow=function(){
$scope.entity.specificationOptionList.push({});
}
<button type="button" class="btn btn-default" title="新建"
ng-click="addTableRow()"><i class="fa fa-file-o"></i> 新建</button>
<tr ng-repeat="pojo in entity.specificationOptionList">
<td><input type="checkbox"></td>
<td>
<input ng-model="pojo.optionName" class="form-control" placeholder="规格选项">
</td>
<td>
<input ng-model="pojo.orders" class="form-control" placeholder="排序">
</td>
</tr>
<button type="button" class="btn btn-default" title=" 新 建 " data-toggle="modal"
data-target="#editModal"
ng-click="entity={'specificationOptionList':[]}"><i
class="fa fa-file-o"></i> 新建</button>
//批量选项删除
$scope.deleTableRow=function(index){
$scope.entity.specificationOptionList.splice(index,1);//删除
}
<button type="button" class="btn btn-default" title="删除"
ng-click="deleTablenRow($index)"><i class="fa fa-file-o"></i> 删除</button>
<insert id="insert" parameterType="com.pinyougou.pojo.TbSpecification" >
<selectKey resultType="java.lang.Long" order="AFTER" keyProperty="id">
SELECT LAST_INSERT_ID() AS id
</selectKey>
insert into tb_specification (id, spec_name)
values (#{id,jdbcType=BIGINT}, #{specName,jdbcType=VARCHAR})
</insert>
package com.pinyougou.pojogroup;
import java.io.Serializable;
import java.util.List;
import com.pinyougou.pojo.TbSpecification;
import com.pinyougou.pojo.TbSpecificationOption;
/**
* 规格组合实体类
* @author Administrator
*
*/
public class Specification implements Serializable {
private TbSpecification specification;
private List<TbSpecificationOption> specificationOptionList;
public TbSpecification getSpecification() {
return specification;
}
public void setSpecification(TbSpecification specification) {
this.specification = specification;
}
public List<TbSpecificationOption> getSpecificationOptionList() {
return specificationOptionList;
}
public void setSpecificationOptionList(List<TbSpecificationOption>
specificationOptionList) {
this.specificationOptionList = specificationOptionList;
}
}
/**
* 增加
*/
public void add(Specification specification);
/**
* 增加
*/
@Override
public void add(Specification specification) {
specificationMapper.insert(specification.getSpecification());//插入规格
//循环插入规格选项
for(TbSpecificationOption
specificationOption:specification.getSpecificationOptionList()){
specificationOption.setSpecId(specification.getSpecification().getId());//设置规
格 ID
specificationOptionMapper.insert(specificationOption);
}
}
/**
* 增加
* @param specification
* @return
*/
@RequestMapping("/add")
public Result add(@RequestBody Specification specification){
try {
specificationService.add(specification);
return new Result(true, "增加成功");
} catch (Exception e) {
e.printStackTrace();
return new Result(false, "增加失败");
}
}
<table class="table table-bordered table-striped" width="800px">
<tr>
<td>规格名称</td>
<td>
<input ng-model="entity.specification.specName"
class="form-control" placeholder="规格名称" >
</td>
</tr>
</table>
<button class="btn btn-success" data-dismiss="modal" aria-hidden="true"
ng-click="save()">保存</button>
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |