<—start—> 
编写crm的webservice接口,实现客户信息保存操作。在CustomerService接口中新增一个服务接口,用于添加客户注册的信息。

1 @Path("/customer")
2 @POST
3 @Consumes({ "application/xml", "application/json" })
4 public void regist(Customer customer);

在实现类中,只需要调用dao的save方法保存以下就可。

1 @Override
2 public void regist(Customer customer) {
3     System.out.println(customer);
4     customerRepository.save(customer);
5 }

因为save方法jpa接口中默认就有,所以不需要自定义去创建方法。 
接下来就是在CustomerAction类中调用服务了。 
调用webservice连接crm保存客户信息:发送json类型的数据,调用post方法将customer传递过去,客户注册就要保存到后台数据库,所以用post方法去添加。

1 @ParentPackage("json-default")
 2 @Namespace("/")
 3 @Controller
 4 @Scope("prototype")
 5 public class CustomerAction2 extends BaseAction<Customer> {
 6     @Action(value="customer_sendSms")
 7     public String sendSms() throws IOException{
 8         //生成短信验证码
 9         String randomCode = RandomStringUtils.randomNumeric(4);
10         //将短信验证码保存到session中
11         ServletActionContext.getRequest().getSession().setAttribute(model.getTelephone(),randomCode);
12         //编辑短信内容
13         String msg = "你好!本次获取的验证码位:"+randomCode;
14         //调用SMS服务发送短信
15         //String result = SmsUtils.sendSmsByHTTP(model.getTelephone(),msg);
16         String result = "000/XXX";
17         if(result.startsWith("000")){
18             //以"000"开头表示短信发送成功
19             return NONE;
20         }else{
21             //发送失败,就抛出一个运行期异常
22             throw new RuntimeException("短信发送失败,信息码:"+result);
23         }
24     }
25 
26     //属性驱动接收页面填写的验证码
27     private String checkCode;
28     public void setCheckCode(String checkCode) {
29         this.checkCode = checkCode;
30     }
31     @Action(value="customer_regist",results={@Result(name="success",type="redirect",location="signup_success.html"),
32             @Result(name="input",type="redirect",location="signup.html")})
33     public String regist(){
34         //先校验短信验证码,如果不通过就跳回登录页面
35         //从session中获取之前生成的短信验证码
36         String checkcodeSession = (String) ServletActionContext.getRequest().getAttribute(model.getTelephone());
37         if(checkcodeSession==null||!checkcodeSession.equals(checkCode)){
38             System.out.println("短信验证码错误!");
39             //短信验证码错误
40             return INPUT;
41         }
42         //调用webservice连接crm保存客户信息
43         WebClient.create("http://localhost:9002/crm_management/services/customerService/customer").type(MediaType.APPLICATION_XML)
44         .post(model);
45         System.out.println("客户注册成功...");
46         return SUCCESS;
47     }
48 }

<—end—>