1. 程式人生 > >簡單的controller方法和action方法

簡單的controller方法和action方法

不同系統的controller方法和對應的action方法都不一樣,但是基本知識呼叫路徑和介面的定義方法有區別,方法中的編寫是一樣的,post和get定義,介面引數的定義,路徑的編寫和註解的使用

1.

Controller

Post

@RestController

@RequestMapping("/store")

public class StoreController extends BaseController {

    @Autowired

    private StoreService service;

    @RequestMapping(value = "/getStoreByCode",method ={RequestMethod.POST})

    public BaseResponseVo getStoreByCode(@RequestBody String code){

        List<Map<String,Object>> list=service.getStoreByCode(code);

        return  BaseResponseVo.success(list);

    }

}

Get

   @RequestMapping(value = "/getContractType/{carSymbol}",method = {RequestMethod.GET})

    public BaseResponseVo getContractType(@PathVariable String carSymbol){

        RentPlanQo rentPlanQo = new RentPlanQo();

        rentPlanQo.setCarSymbol(carSymbol);

        Map<String, Object> map = stockService.getContractType(rentPlanQo);

        if(map==null||map.get("contractType")==null||"".equals(map.get("contractType"))){

            throw new BaseException("111", "未查詢到資訊!");

        }

        map.remove("billingCompany");

        map.remove("rate");

                   return BaseResponseVo.success(map);

    }

2.這個是使用的rpc,介面路徑直接定義

   /**
     * 查詢所有可用的銀行基礎資訊
     * @return
     */
    @RSAnnotation(value = "hshcmdm.bank.queryBankAllValid",remark="銀行基礎資訊")
    public List<BankDTO> queryBankAllValid() {
        List<BankModel> bankList= bankMapper.queryBankAllValid();
        List<BankDTO> resultBank=new ArrayList<>();
        for (BankModel bm:bankList){
            BankDTO dto=new BankDTO();
            dto.setCode(bm.getCode());
            dto.setName(bm.getName());
            dto.setAbbreviation(bm.getAbbreviation());
            resultBank.add(dto);
        }
        return resultBank;
    }
        @RSAnnotation(value = "hshcdispatch.dispatchOrder.purCancel", remark = "採購取消")
    public Res purCancel(String orderNo, String userId) {
        logger.info("遠端服務--採購取消,客戶訂單號為:"+orderNo);
        return dispatchOrderService.purCancel(orderNo, userId);
    }

@Service
public class TestRS extends AbstractRS{
//遠端服務地址
    @RSAnnotation("hshcstore.test.test")
    public Object test(Object o1){
        System.out.println(o1);
        return TimeUtil.getNowTimeAllStr()+"=>"+o1;
    }

    public static void main(String[] args) {
//        Object obj= RemoteClientUtil.getClient("http://localhost:9000")
//                .exe("hshcstore.test.test","wodeceshi");  測試一下
        Object obj= RemoteClientUtil.exe("hshcstore.test.test","wodeceshi");
        System.out.println(obj);
    }


}
 

3.自定義註解,無框架

自定義註解中的郵箱和type設定了許可權和不可為空狀態,配置中定義

@aPermission(name =  { "業務管理", "排程管理", "查詢" })
@aDev(code = "sun", email = "[email protected]", name = "sun")
@aAuth(type = aAuthType.LOGIN)
public Reply getDispatchPage(){
   Map<String, Object> map = _getParameters();
   Page page = service.getDispatchPage(map);
   return new ReplyAjaxPage(page);
}