1.前端页面显示技巧
数据库中存的是0 1 2这样的值来代表不同的数据时,前端显示需要进行多个if判断再将对应的文本显示到页面上,此时可以这样做:
1.controller.js中:
//添加state数组
$scope.status=['未审核','已审核','审核未通过','关闭'];
2.页面中:
//显示
{{status[entity.auditStatus]}}
当然,多个数值时也可以这样做:
1.controller.js中:
//前端代码用ID去查询后端
$scope.itemCatList=[];//商品分类列表
//加载商品分类列表
$scope.findItemCatList=function(){
itemCatService.findAll().success(
function(response){
for(var i=0;i<response.length;i++){
$scope.itemCatList[response[i].id]=response[i].name;
}
}
);
}
此时返回的分页结果以数组形式再次封装。
2.html 页面,增加初始化调用
<body class="hold-transition skin-red sidebar-mini" ng-app="pinyougou" ng-controller="goodsController" ng-init="findItemCatList()">
3.修改列表
<td>{{itemCatList[entity.category1Id]}}</td>
<td>{{itemCatList[entity.category2Id]}}</td>
<td>{{itemCatList[entity.category3Id]}}</td>
2.页面跳转
1.Controller中引入$location服务
app.controller('goodsController',function($scope,$location){
$scope.findOne=function(){
var id= $location.search()['id'];//获取参数值
if(id==null){
return ;
}
goodsService.findOne(id).success(
function(response){
$scope.entity= response;
}
);
}
}
2.html页面上添加指令
<body class="hold-transition skin-red sidebar-mini" ng-app="pinyougou" ng-controller="goodsController" ng-init="selectItemCat1List();findOne()">
3.地址栏输入 : ?前要加# ,则是angularJS的地址路由的书写形式
如:http://localhost:9102/admin/goods_edit.html#?id=149187842867969
4.html表格行的修改按钮
<a href="goods_edit.html#?id={{entity.id}}" class="btn bg-olive btn-xs">修改</a>
此时{{entity.id}}放在引号中,而不是拼接字符串能直接获取数据
3.注解配置事务
1.applicationContext-tx.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 开启事务控制的注解支持 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
2.在service层中添加@Transactional注解