JFinal学习

本文介绍如何使用JFinal框架进行应用开发,并通过极光推送实现消息推送功能。包括控制器编写、配置文件设置及异常处理等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 jfinal-1.9-bin.jar

2 继承Controller编写控制器

 

public void sendJPushToXXX() {
  String userId = getPara("userId");//程序片段获取传参,不要在方法名里直接写上参数,这样是会报404
  String alert = getPara("alert");
  if(userId == null || alert == null){
    ...
    renderText("false");
    return;
  }
  PushPayload payload = buildPushObject_ios_android_alias(userId,alert);
  try {
    PushResult result = jpushClient.sendPush(payload);
    LOG.info("sendJPushToOne:result code - " + result.getResponseCode());
    LOG.info("Got result - " + result);
    if(result.getResponseCode()==200){//发送成功
      renderText("true");
      return;
    }
  } catch (APIConnectionException e) {
    LOG.error("Connection error. Should retry later. ", e);
  } catch (APIRequestException e) {
    LOG.error("Error response from JPush server. Should review and fix it. ", e);
    LOG.info("HTTP Status: " + e.getStatus());
    LOG.info("Error Code: " + e.getErrorCode());
    LOG.info("Error Message: " + e.getErrorMessage());
    LOG.info("Msg ID: " + e.getMsgId());
  }
  renderText("false");
}

 

3 JFinalConfig(configRoute方法添加访问路由):

public class DefaultConfig extends JFinalConfig {  

    ......

    @Override  

    public void configRoute(Routes me) {  

         me.add("/sayHello", HelloController.class);    

    }  

}  

 

4 Web.xml配置

<filter>

<filter-name>jfinal</filter-name>

<filter-class>com.jfinal.core.JFinalFilter</filter-class>

<init-param>

<param-name>configClass</param-name>

 <param-value>xxx.xxx.DefaultConfig</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>jfinal</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

5 访问 http://xxxx/sayHello

转载于:https://www.cnblogs.com/yanfly/p/6233642.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值