小编kak*_*ali的帖子

restTemplate请求到Netty Server挂起线程

RestTemplate示例如下.

public class SimpleClient {

    private final String URL;
    private AsyncRestTemplate rest = new AsyncRestTemplate(new Netty4ClientHttpRequestFactory());
    private RestTemplate restTemplate = new RestTemplate(new Netty4ClientHttpRequestFactory());

    public SimpleClient(String url) {
        this.URL = url;
        Netty4ClientHttpRequestFactory nettyFactory = new Netty4ClientHttpRequestFactory();
        try {
                    nettyFactory.setSslContext(SslContextBuilder.forClient().build());
        } catch (SSLException e) {
            e.printStackTrace();
        }
        rest = new AsyncRestTemplate(nettyFactory);
    }

    @Override
    public ResponseEntity<ResponseData> doSendByPOST(RequestData data,Class<ResponseData> clazz) {

        List<HttpMessageConverter<?>> messageConvertors = new ArrayList<>();
        messageConvertors.add(new MappingJackson2HttpMessageConverter());

        rest.setMessageConverters(messageConvertors);
        restTemplate.setMessageConverters(messageConvertors);

        HttpHeaders headers = new HttpHeaders();
        ObjectMapper objectMapper = new ObjectMapper();
        StringWriter writer = new …
Run Code Online (Sandbox Code Playgroud)

java spring netty resttemplate asyncresttemplate

11
推荐指数
1
解决办法
557
查看次数

以HTML格式发送电子邮件内容

我必须发送一封电子邮件,其中包含html中的所有内容,可以在电子邮件中显示为HTML.我能够发送带有JavaMailSenderImplSpring Framework SimpleMailMessage的电子邮件,但我发送的电子邮件以简单的html文本显示,如下所示

<html><body><h1>Hello</h1></body></html>
Run Code Online (Sandbox Code Playgroud)

而不是HTML页面的形式.

请告诉我如何将其作为HTML发送以及如何以HTML格式显示.

java email spring

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

使用java创建一个4位数的随机数,不带数字重复

我用java创建了一个代码来创建一个没有重复数字的随机4位数字,我写的代码如下: -

Random r = new Random();
d1 = r.nextInt(9);
d2 = r.nextInt(9);
d3 = r.nextInt(9);
d4 = r.nextInt(9);
while(d1==d2||d1==d3||d1==d4||d2==d3||d2==d4||d3==d4)
{
    if(d1==d2||d2==d3||d2==d4)
    {
        d2 = r.nextInt(9);
    }
    if(d1==d3||d2==d3||d3==d4)
    {
        d3 = r.nextInt(9);
    }
    if(d1==d4||d2==d4||d3==d4)
    {
        d4 = r.nextInt(9);
    }
}   
System.out.println(d1+""+d2+""+d3+""+d4);
Run Code Online (Sandbox Code Playgroud)


以下是测试用例(由...生成System.out.println(R1+""+R2+""+R3+""+R4);)如下: -

 0123 |  OK as required
 1234 |  OK as required
 2123 |  not OK because 2 is present more than one time 
 9870 |  OK as required
 0444 |  not OK because 4 is present …
Run Code Online (Sandbox Code Playgroud)

java random numbers

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

如何在spring boot controller中执行sql语句?

我想在spring boot controller类中执行sql语句,而不是在jpa存储库中定义任何方法.我想要使​​用的声明是

SELECT UUID();
Run Code Online (Sandbox Code Playgroud)

此语句与数据库相关,并且与特定实体无关.

如果任何人都能通过提供上述语句的执行解决方案,那将是很好的

  1. 弹簧控制器类
  2. jpa存储库(如果推荐)

更新

控制器:

@Autowired
JdbcTemplate jdbcTemplate;

@RequestMapping(value = "/UUID", method = RequestMethod.GET)
public ResponseEntity<String> getUUID() {
    String uuid = getUUID();
    return buildGuestResponse(uuid);
}

public String getUUID(){
    UUID uuid = (UUID)jdbcTemplate.queryForObject("select UUID()", UUID.class);
    return uuid.toString();
}
Run Code Online (Sandbox Code Playgroud)

java mysql uuid spring spring-boot

5
推荐指数
1
解决办法
9324
查看次数

带有可选参数的Spring @RequestMapping

我的控制器在requestmapping中有可选参数存在问题,请在下面的控制器上查看:

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Books>> getBooks() {
    return ResponseEntity.ok().body(booksService.getBooks());
}

@GetMapping(
    produces = MediaType.APPLICATION_JSON_VALUE,
    params = {"from", "to"}
)
public ResponseEntity<List<Books>>getBooksByFromToDate(
    @RequestParam(value = "from", required = false) String fromDate,
    @RequestParam(value = "to", required = false) String toDate) 
{
    return ResponseEntity.ok().body(bookService.getBooksByFromToDate(fromDate, toDate));
}
Run Code Online (Sandbox Code Playgroud)

现在,当我发送如下请求时:

/getBooks?from=123&to=123
Run Code Online (Sandbox Code Playgroud)

没关系,请求转到“ getBooksByFromToDate”方法,但是当我使用发送类似的东西时:

/getBooks?from=123
Run Code Online (Sandbox Code Playgroud)

要么

/getBooks?to=123
Run Code Online (Sandbox Code Playgroud)

转到“ getAlerts”方法

是否可以在@RequestMapping中使可选参数= {“ from”,“ to”}?有什么提示吗?

java api rest spring spring-boot

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

使用 Spring Data MongoDB 在事务中调用两个不同 ReactiveMongoRepository 中的方法?

在 Spring Data MongoDB 中使用反应式编程模型时,可以执行如下事务:

Mono<DeleteResult> result = template.inTransaction()                                      
    .execute(action -> action.remove(query(where("id").is("step-1")), Step.class)); 
Run Code Online (Sandbox Code Playgroud)

但是 Spring Data MongoDB 也支持“reactive repositories”,例如:

public interface PersonRepository extends ReactiveMongoRepository<Person, String>

  Flux<Person> findByLocationNear(Point location, Distance distance);
}
Run Code Online (Sandbox Code Playgroud)

public interface CarRepository extends ReactiveMongoRepository<Car, String>

  Flux<Car> findByYear(int year);
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,鉴于你有ReactiveMongoRepository's,你能以某种方式利用 MongoDB 事务,例如在同一个事务中插入 aPerson和吗Car(在这种情况下使用PersonRepositoryCarRepository)?如果是这样,你如何做到这一点?

java spring mongodb spring-boot spring-data-mongodb-reactive

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

重置 recaptcha 时出现问题 - 无法读取代码的 null 属性“重置”

React-google-recaptcha 版本:2.0.0-rc.1

我在重置验证码时遇到问题

我正在使用功能组件

代码摘录如下

// imports etc.. here
const Login: NextPage = (props:any) => {

// othere initializations here...

const recaptchaInputRef:any = React.createRef();

const handleSubmit = async (event) => {

      // some if condition
     // and else
     // and inside there
     recaptchaInputRef.current.reset();

}

return (
        <React.Fragment>

               <form onSubmit={e => handleSubmit(e)}>

               // other components and elements

              <ReCAPTCHA
                 ref={recaptchaInputRef}
                 sitekey={props.recaptchaKey}
                 onChange={ onChange }
                 onExpired={ onExpired }
                 />

              <Button type="submit">Sign In</Button>
              </form>
        </React.Fragment>
);

Run Code Online (Sandbox Code Playgroud)

现在的问题是,我得到 - Cannot read property 'reset' of null …

recaptcha reactjs next.js react-google-recaptcha

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

如何在 JavaScript 中使用 concat() 方法在字符串之间留出空格

我想使用 concat() 方法连接多个字符串,它工作正常,但如何在它们之间留出空白

<HTML>
    <head>
       <title></title>
    </head>
    <body>
       <label id="label_one" style="color:blue;"></label><br/>
       <label id="label_two" style="color:blue;"></label><br/>
       <label id="label_three" style="color:blue;"></label><br/>
       <script>
           var one = "abc";
           var two = "def";
           var three = one.concat(two)
           var four = three.length;
           var variableLen = one.concat(three, four);
           document.getElementById("label_one").innerHTML = one;
           document.getElementById("label_two").innerHTML = two;
           document.getElementById("label_three").innerHTML = variableLen;
       </script>
    </body>
</HTML>
Run Code Online (Sandbox Code Playgroud)

我的输出是

abcdef6 我希望我的输出像这样abc def 6连接后有空格并使用 JavaScript 的 concate() 方法而不是连接运算符(+)

html javascript

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

无法在JpaRepository的代码中使用findOne()

我有一个与Personne班有关的项目

package com.example.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@SuppressWarnings("serial")
@Entity  
public class Personne implements Serializable {

    @Id
    @GeneratedValue
    private Long id;
    @Column(length = 80, name = "NOM")
    private String nom;
    @Column(length = 80, name = "PRENOM")
    private String prenom;
    @Column(length = 80, name = "ADRESSE")
    private String adresse;
    @Column(length = 80, name = "EMAIL")
    private String email;
    @Column(length = 80, name = "TELEPHONE")
    private String telephone;

    public Long getId() {
        return id;
    }

    public void …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate spring-data-jpa spring-boot

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

在 Spring 5.0 中设置 Spring 的 RestTemplate 的基本 URL/URI

RestTemplate在 Spring Boot 2 应用程序中使用 Spring 5,并尝试在其上设置基本 URL/URI,这样我就不必在每个请求前面添加它。这也允许我根据属性设置该值。

以前的版本ReleaseTemplate允许您通过构造函数设置基本 url(例如new ReleaseTemplate(baseUrl))。但现在情况已不再如此。

我看到该类DefaultUriTemplateHandler有一个setBaseUrl()AbstractUriTemplateHandler接口继承的类,但该类已被弃用。建议的替换类DefaultUriBuilderFactory没有任何此类方法。

任何建议,将不胜感激。谢谢。

java spring spring-boot

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