生活随笔
收集整理的這篇文章主要介紹了
WebService实例-CRM系统提供WebService实现用户注册功能
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<—start—>
編寫crm的webservice接口,實現客戶信息保存操作。在CustomerService接口中新增一個服務接口,用于添加客戶注冊的信息。
@Path(
"/customer")
@POST
@Consumes({
"application/xml",
"application/json" })
public void regist(Customer customer);
在實現類中,只需要調用dao的save方法保存以下就可。
@Override
public void regist(Customer customer) {System.
out.println(customer);customerRepository.save(customer);
}
因為save方法jpa接口中默認就有,所以不需要自定義去創建方法。
接下來就是在CustomerAction類中調用服務了。
調用webservice連接crm保存客戶信息:發送json類型的數據,調用post方法將customer傳遞過去,客戶注冊就要保存到后臺數據庫,所以用post方法去添加。
@ParentPackage(
"json-default")
@Namespace(
"/")
@Controller
@Scope(
"prototype")
public
class CustomerAction2 extends BaseAction<Customer> {@Action(value=
"customer_sendSms")public String sendSms()
throws IOException{String randomCode = RandomStringUtils.randomNumeric(
4);ServletActionContext.getRequest().getSession().setAttribute(model.getTelephone(),randomCode);String msg =
"你好!本次獲取的驗證碼位:"+randomCode;String result =
"000/XXX";
if(result.startsWith(
"000")){
return NONE;}
else{
throw new RuntimeException(
"短信發送失敗,信息碼:"+result);}}
private String checkCode;public void setCheckCode(String checkCode) {
this.checkCode = checkCode;}
@Action(value=
"customer_regist",results={
@Result(name=
"success",
type=
"redirect",location=
"signup_success.html"),
@Result(name=
"input",
type=
"redirect",location=
"signup.html")})public String regist(){String checkcodeSession = (String) ServletActionContext.getRequest().getAttribute(model.getTelephone());
if(checkcodeSession==
null||!checkcodeSession.equals(checkCode)){System.out.println(
"短信驗證碼錯誤!");
return INPUT;}WebClient.create(
"http://localhost:9002/crm_management/services/customerService/customer").
type(MediaType.APPLICATION_XML).post(model);System.out.println(
"客戶注冊成功...");
return SUCCESS;}
}
<—end—>
總結
以上是生活随笔為你收集整理的WebService实例-CRM系统提供WebService实现用户注册功能的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。