1.Action层
@Controller
@Namespace("/")
@Scope("prototype")
@ParentPackage("json-default")
public class WayBillAction extends BaseAction<WayBill>{
public Integer wayBillIdcopy;
public voidsetWayBillIdcopy(Integer wayBillIdcopy) {
this.wayBillIdcopy =wayBillIdcopy;
}
@Autowired
privateWayBillService wayBillService;
@Action(value="waybill_quicksave",results={@Result(name="success",type="json")})
public String quicksave(){
wayBillService.save(getModel());
return "success";
}
@Action(value="waybill_save",results={@Result(name="success",type="redirect",location="./pages/take_delivery/waybill.html")})
public String save(){
if(wayBillIdcopy!=null){
getModel().setId(wayBillIdcopy);
}
wayBillService.save(getModel());
return"success";
}
@Action(value="wayBill_findbywaybillnum",
results={@Result(name="success",type="json",params={"excludeNullProperties","true"})})
public String findbywaybillnum(){
WayBillwaybill=wayBillService.findbywaybillnum(getModel().getWayBillNum());
Map<String,Object> map = new HashMap<String, Object>();
if (waybill != null) {
map.put("success",true);
map.put("waybill",waybill);
} else {
map.put("success",false);
}
ActionContext.getContext().getValueStack().push(map);
return"success";
}
}
1.Controller,@Component
控制层:component也行,但是为了区分清楚,使用controller表示这是控制层
@Scope("prototype")
多例模式,对应的单例模式(Singleton);一般来说Action都是多例的,因为每个人使用的都是不同的浏览器,保存不同的数据
@Namespace("/")
Namespace和Action一起使用,namespace表示命名空间,接受请求的url路径和这个必须对应,不然找不到对应的Action
@ParentPackage("json-default")
Parentpackage表示父包,继承于这个父包,可以使用这个父包里面的一些对应的方法(默认是struts-default),如果使用了json必须继承json-default
@Action
Namespace和Action一起使用,namespace表示命名空间,接受请求的url路径和这个必须对应,不然找不到对应的Action
Action里面的参数设置:value:表示接受的请求的url对应的值
里面results对应返回的结果集
@Result(name="success",type="json",params={"excludeNullProperties","true"})}
Results里面是result集,
Name对应return的String
Type对应的是result的方式.默认是请求转发forward
Forward:请求转发
redirect:重定向
json:返回的是接送数据,直接push在值栈里面
params:配置结果集的一些参数
excludeNullProperties:返回值中为null的不返回
@Autowired
自动注入,如果接口有多个实现类.可以使用autowire的和qualifier(指定名字)一起使用,
也可以使用resource指定名字自动注入
2. @Service
@Transactional
Service表示这一层时业务层
Transactional:开启事务
Repository:表示这是业务层
@Query:查询,里面可以写查询语句
@Modifying:表示修改