我想写一个简单的正则表达式来检查给定的字符串是否存在任何特殊字符.我的正则表达式有效,但我不知道为什么它也包含所有数字,所以当我输入一些数字时它会返回错误.
我的代码:
//pattern to find if there is any special character in string
Pattern regex = Pattern.compile("[$&+,:;=?@#|'<>.-^*()%!]");
//matcher to find if there is any special character in string
Matcher matcher = regex.matcher(searchQuery.getSearchFor());
if(matcher.find())
{
errors.rejectValue("searchFor", "wrong_pattern.SearchQuery.searchForSpecialCharacters","Special characters are not allowed!");
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个包含一列的简单表格。
我创建一个新行,并在每行中创建一个新段落。问题是每一行都以一个空行开头 - 我猜是新段落创建了它。
我之前尝试设置间距、缩进等,但没有成功。
for (int i=0; i<questions.size(); i++) {
Question question = questions.get(i);
XWPFTableRow row = table.getRow(i);
XWPFTableCell cell = row.getCell(0);
XWPFParagraph paragraph = cell.addParagraph();
XWPFRun run = paragraph.createRun();
run.setText(question.getQuestion());
}
Run Code Online (Sandbox Code Playgroud)
新段落是否会创建新的空行?
该表看起来像这样:
我有一个使用BigDecimal的比例和RoundingMode舍入数字的问题.
这是我的一段代码:
BigDecimal taxAmount = new BigDecimal("0.8445");
taxAmount = taxAmountPrecision.setScale(2, RoundingMode.HALF_UP);
Run Code Online (Sandbox Code Playgroud)
如果我把0.845放得很好,但如果有0.8445,则taxAmount为0.84.
它应该是0.8445 - > 0.845 - > 0.85.
我知道有很多这样的帖子,但我尝试了很多解决方案,但对我来说没有任何效果。
我正在使用 Firebase Cloud Messaging 发送通知。通知到达,但它打开了主要活动,而不是我想要的活动。
我尝试再尝试,但在开始适当的活动时总是失败。尝试了不同的 Intent 或 PendingIntent 设置,尝试了 click_action,对我来说没有任何效果。
我认为它甚至没有进入我的 FirebaseMessagingService,但我在 Firebase 指令中做了所有事情。
显现:
<service
android:name="com.packagename.FirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity android:name="com.packagename.NotificationActivity">
<action android:name="OPEN_ACTIVITY_1" />
<category android:name="android.intent.category.DEFAULT" />
</activity>
Run Code Online (Sandbox Code Playgroud)
Firebase 消息服务:
public class FirebaseMessagingService extends FirebaseMessagingService {
private static String TAG = "Firebase";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
if(remoteMessage.getNotification()!=null){
Log.d(TAG,"Message body : "+remoteMessage.getNotification().getBody());
sendNotification(remoteMessage.getNotification().getBody(), remoteMessage.getNotification().getTitle());
} …
Run Code Online (Sandbox Code Playgroud) java ×3
android ×1
apache-poi ×1
bigdecimal ×1
firebase ×1
ms-word ×1
regex ×1
rounding ×1
xwpf ×1