小编Ank*_*ani的帖子

使用Hibernate注释验证移动号码

我有一个名为User的实体,我想验证手机号码字段

手机号码字段不是强制性的,可以留空,但应该是10位数字.

如果用户输入的长度小于10位,则应抛出错误.

以下是我的用户类.

public class User {

    @Size(min=0,max=10)
    private String mobileNo;

}
Run Code Online (Sandbox Code Playgroud)

当我如上所述使用@Sized注释时,我可以验证大于10的值,但如果用户输入的数字少于10位,则不会引发错误.

我的要求是,如果用户将mobileNo字段留空,该字段有效,但如果输入了值,则验证应确保输入的数字仅为10位数和10位数.

我应该使用哪个注释来满足此要求?

java phone-number hibernate-validator bean-validation

12
推荐指数
3
解决办法
3万
查看次数

Java正则表达式匹配具有特殊字符的精确单词

我有用户输入的关键字列表,它们可能包含特殊字符等$, #, @, ^, &,.

根据我的要求,当我收到短信列表时,我需要搜索每条短信中的所有关键字.

我们需要匹配完全关键字.

案例1:简单关键字 - 简单消息

我曾经\b匹配完全关键字,它工作正常.

public static void main(String[] args) {
        String patternStr =  "(?i)\\bHello\\b";

        Pattern pattern = Pattern.compile(patternStr);

        List<String> strList = new ArrayList<String>();
        strList.add("HHello Message");
        strList.add("This is Hello Message ");
        strList.add("Now Hellos again.");

        for(String str : strList) {
            Matcher matcher = pattern.matcher(str);
            System.out.println(">> "+matcher.find());
        }
    }
Run Code Online (Sandbox Code Playgroud)

按预期输出

>> false
>> true
>> false
Run Code Online (Sandbox Code Playgroud)

案例2:简单关键字 - 具有特殊字符的消息

现在,如果我在跟踪消息上面运行相同的代码,那么它没有按预期工作.

List<String> strList = new …
Run Code Online (Sandbox Code Playgroud)

java regex string

9
推荐指数
1
解决办法
2万
查看次数

Spring Boot + 具有自定义提供程序的安全 OAuth2.0 客户端

我正在 Spring Boot + Security(版本 5)应用程序中为自定义 OAuth2 提供程序创建 OAuth2.0 客户端。

下面是application.properties包含所有配置的,并且在我的项目中没有额外的配置类。

spring.security.oauth2.client.registration.xxxxxxxxx.client-id=XXXXXXXXXX
spring.security.oauth2.client.registration.xxxxxxxxx.client-secret=XXXXXXXXXX
spring.security.oauth2.client.registration.xxxxxxxxx.scope=openid
spring.security.oauth2.client.registration.xxxxxxxxx.redirect-uri-template=http://localhost:8080/login/oauth2/code/xxxxxxxxx
spring.security.oauth2.client.registration.xxxxxxxxx.client-name=xxxxxxxxx
spring.security.oauth2.client.registration.xxxxxxxxx.provider=xxxxxxxxx
spring.security.oauth2.client.registration.xxxxxxxxx.client-authentication-method=basic
spring.security.oauth2.client.registration.xxxxxxxxx.authorization-grant-type=authorization_code

spring.security.oauth2.client.provider.xxxxxxxxx.authorization-uri=https://api.xxxxxxxxx.com/authorize
spring.security.oauth2.client.provider.xxxxxxxxx.token-uri=https://api.xxxxxxxxx.com/token
spring.security.oauth2.client.provider.xxxxxxxxx.user-info-uri=https://api.xxxxxxxxx.com/userinfo?schema=openid
spring.security.oauth2.client.provider.xxxxxxxxx.user-name-attribute=name
spring.security.oauth2.client.provider.xxxxxxxxx.user-info-authentication-method=header
Run Code Online (Sandbox Code Playgroud)

当我点击http://localhost:8080/它时,它会正确重定向到提供商的登录页面,成功登录后它会重定向回我的应用程序。

现在的问题是当它重定向时它会显示以下错误消息。 在此输入图像描述

我已经用谷歌搜索了这个错误,但没有得到任何正确的答案。此外,OAuth2 提供商没有共享此类 URL。

经过研究,我发现我需要设置以下属性。应该由Auth Provider 提供吗? spring.security.oauth2.client.provider.pepstores.jwk-set-uri

我在配置中到底缺少什么?

oauth-2.0 oauth2client spring-security-oauth2 spring-oauth2

9
推荐指数
1
解决办法
2万
查看次数

Apache AXIS在解析时忽略/跳过其他元素

我们使用第三方的Web服务.每当他们像添加新元素一样更新XML模式时,我们都会收到以下错误消息.

"SAXException:无效的元素......"

AXIS中是否有任何方法可以在解析时跳过XML上收到的其他元素?

我之前使用AXIS生成了Web服务客户端,用于接收XML,如下所示

<Flight>
   <AirlineCode>AB</AirlineCode> 
</Flight>
Run Code Online (Sandbox Code Playgroud)

一切都很好.但现在我得到一个额外的标签作为回应.

<Flight>
   <AirlineCode>AB</AirlineCode> 
   <OtherCode>XX</OtherCode> 
</Flight>
Run Code Online (Sandbox Code Playgroud)

为此,我得到"无效元素"例外.

谢谢

java apache axis axis2

6
推荐指数
1
解决办法
2054
查看次数

XSLT跳过重复元素

我是XSLT的初学者.

我的源XML如下:

<Passengers>
    <Passenger type="A" id="P1"/>
    <Passenger type="A" id="P2"/>
    <Passenger type="B" id="P3"/>
    <Passenger type="C" id="P4"/>
</Passengers>
Run Code Online (Sandbox Code Playgroud)

输出应如下:

<Pax_Items>
     <Item>
         <Type>A</Type>
         <Count>2</Count>
     </Item>
     <Item>
         <Type>B</Type>
         <Count>1</Count>
     </Item>
     <Item>
         <Type>C</Type>
         <Count>1</Count>
     </Item>
</Pax_Items>
Run Code Online (Sandbox Code Playgroud)

我已经创建了XSLT,如下所示

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0" exclude-result-prefixes="xmlns">

    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
        <xsl:variable name="filter" select="'TK,AJ'"/>

    <xsl:template match="Passengers">
        <xsl:element name="Pax_Items">
            <xsl:apply-templates select="Passenger"/>
        </xsl:element>
    </xsl:template>

        <xsl:template match="Passenger">
              <xsl:element name="Item">
                     <xsl:element name="Type">
                           <xsl:value-of select="@type"/>
                     </xsl:element>
                     <xsl:element name="Count">
                           <xsl:value-of select="count(//Passenger[@type=current()/@type])"/>
                     </xsl:element>
              </xsl:element>
    </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

使用上面的XSLT我得到以下输出:

<Pax_Items>
  <Item>
    <Type>A</Type>
    <Count>2</Count>
  </Item>
  <Item>
    <Type>A</Type>
    <Count>2</Count>
  </Item>
  <Item> …
Run Code Online (Sandbox Code Playgroud)

java xml xslt transformation

4
推荐指数
1
解决办法
1993
查看次数

XSLT 通过索引获取节点

我是 XSLT 的初学者,我正在使用它来将 XML 转换为 XML

这是我收到的源 XML

源 XML:

<Response>
    <Pax>
        <Id>1</Id>
    </Pax>
    <Pax>
        <Id>2</Id>
    </Pax>
    <Travelers>
        <Traveler>
            <Name>ABC</Name>
        </Traveler>
        <Traveler>
            <Name>XYZ</Name>
        </Traveler>
    </Travelers>
</Response>
Run Code Online (Sandbox Code Playgroud)

我在XSLT下面写过

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

    <xsl:output method="xml" indent="yes" />

    <xsl:template match="Response">
        <xsl:element name="Root">
                <xsl:apply-templates select="Travelers/Traveler"/>
        </xsl:element>
    </xsl:template>

    <xsl:template match="Traveler">
          <xsl:element name="Person">
             <xsl:element name="PId">
                   <xsl:value-of select="//Pax/Id[position()]" />
             </xsl:element>
             <xsl:element name="Name">
                   <xsl:value-of select="Name" />
             </xsl:element>
          </xsl:element>
    </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

输出:

<Root>
  <Person>
    <PId>1</PId>
    <Name>ABC</Name>
  </Person>
  <Person>
    <PId>1</PId>
    <Name>XYZ</Name>
  </Person>
</Root>
Run Code Online (Sandbox Code Playgroud)

我想生成以下 XML 输出

预期输出: …

xslt transformation xslt-1.0

4
推荐指数
1
解决办法
2万
查看次数