小编Dim*_*San的帖子

使用高斯算法的 2016 年 Java 复活节计算器

我正在使用高斯算法制作未来 10 年的复活节计算器。

除了几年之外,它似乎工作得很好。例如,它告诉您 2016 年的复活节将在 2016-03-27,但它将在 2016-05-01。与其他年份搭配效果很好。

这是我的代码:

public class EasterCalculator {
public static void main(String[] args) {
    EasterCalculator obj = new EasterCalculator();
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyy");

    for (int i = 2016; i < 2026; i++) {
        System.out.println("Easter  in " + i + " will be on " + obj.getEasterDate(i).format(formatter));
        System.out.println("Trinity in " + i + " will be on " + obj.getEasterDate(i).plusWeeks(7).format(formatter));
        System.out.println();
    }
}

public LocalDate getEasterDate(int year) {
    int a = year % 19;
    int …
Run Code Online (Sandbox Code Playgroud)

java algorithm

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

使用jQuery更改值

我有以下内容:

<span class="label-info">3</span>
Run Code Online (Sandbox Code Playgroud)

我有以下jquery

var replaceit = $(this).closest(':has(.label-info)').find('.label-info').text();
Run Code Online (Sandbox Code Playgroud)

变量的值始终是一个整数,但不总是3:

ie: 1, 2, 3, 4, 5.
Run Code Online (Sandbox Code Playgroud)

我已经尝试了很多方法,无法获得改变的价值.我的最新尝试是:

return $(this).closest(':has(.label-info)').html().replace(replaceit, (replaceit - 1)); 
Run Code Online (Sandbox Code Playgroud)

我的最终结果是从"lable-info"的当前值中减去1,并用这个新结果切换它.因此,基于3的值的新跨度将成为.

<span class="label-info">2</span>
Run Code Online (Sandbox Code Playgroud)

我该如何实现这一目标?

更新代码更清晰

HTML:

<div>
<span class="lable-info">3</span>
</div>

<div>
   <a class="accept_friend">accept</a>
</div>
Run Code Online (Sandbox Code Playgroud)

JavaScript的:

    $(document).on("click", "a.accept_friend", function() { 
        var checkValue = $(this).closest(':has(.name)').find('.name').text();
        var removeit = $(this).closest(':has(.item)').find('.item').fadeOut();
        var replaceit = $(this).closest(':has(.label-info)').find('.label-info').text();
        $.ajax({
            url: '/includes/accept_friend.php',
            type: 'post',
            data: {checkValue},
            success:function(data){
            return removeit;
            $("a.remove_pending").text(function () {
            return ('.label-info').html().replace(replacei, replaceit); 
        });
    }
Run Code Online (Sandbox Code Playgroud)

笔记:

我没有使用id.我正在上课.有多个具有相同名称的类.所以我必须通过最近的电话.

javascript jquery

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

我们应该在使用 Thymeleaf 时删除 HTML 属性吗?

我正在研究 Thymeleaf 并发现在几乎所有示例中都有 Thymeleaf 的标签值以及标准 HTML 值,例如:

<title th:text="#{product.page.title}">Page Title</title>

<link href="../static/css/bootstrap-3.3.7-dist/bootstrap.min.css" rel="stylesheet"
      th:href="@{/css/bootstrap-3.3.7-dist/bootstrap.css}"/>

<script src="../static/js/jquery-3.1.1.js"
        th:src="@{/js/jquery-3.1.1.js}"></script>
Run Code Online (Sandbox Code Playgroud)

控制器会忽略这些标准标签值,例如Page Titlehref="../static/css/bootstrap-3.3.7-dist/bootstrap.min.css"等,并且不会在页面上呈现。

我想知道 - 将它们留给它们以提高代码可读性是否只是一个好习惯,还是最好将它们删除以清理代码?

因为对于编译器来说,它们是无用的,对渲染结果没有任何影响。

java thymeleaf

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

使用ggplot2绘制时间序列数据

我正在做一个项目,需要使用 ggplot2 来绘制时间序列数据。这是我正在使用的数据集:

欧元

这就是我现在所做的:

library(ggplot2)
library(lubridate)
eur$Date <- as.Date(eur$Date)
ggplot(eur, aes(Date, EUR)) + geom_line()
Run Code Online (Sandbox Code Playgroud)

阴谋

我得到了这个非常奇怪的情节。有人可以帮我解决这个问题吗?

r time-series ggplot2 lubridate

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

VisualStudio Code启动时全黑

当我启动 VSCode 时,它​​是完全黑色的,你看不到任何东西。但是当我输入某些内容并退出程序时,它会询问您是否要保存更改。我输入的单词被保存了!一切正常,但屏幕完全黑。

有谁知道如何解决它?

黑屏图片

screen visual-studio-code

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

Thymeleaf表单验证的唯一值,如何传递错误以查看

我正在为我的申请创建注册表。我想检查用户名是否唯一。我这样做

@Transactional
@RequestMapping(value = "/users/", method = RequestMethod.POST)
public String createUser(@ModelAttribute("user") @Valid User user, BindingResult bindingResult){


    if (bindingResult.hasErrors() || !userService.isUniqueUsername(user)) {
        ModelAndView modelAndView = new ModelAndView("redirect:/admin/createnew");
        modelAndView.addObject(bindingResult.getFieldErrors());
        ObjectError objectError = new ObjectError("ERROR", "Username exists!");
        bindingResult.addError(objectError);
        return "user-create";
    }
Run Code Online (Sandbox Code Playgroud)

我知道我的逻辑在这里是错误的,因为我没有将绑定结果提供给“用户创建”视图。

<div th:if="${#fields.hasErrors('username')}" th:errors="*{username}">
    <p class="bg-danger text-center">Username error!</p>
</div>
Run Code Online (Sandbox Code Playgroud)

所以atm我只能显示诸如@NotNull和@Size之类的注释中的错误,但是我如何传递信息以查看服务器说的用户名不是唯一的呢?

java spring thymeleaf spring-boot

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

Java BigInteger modInverse和modPow

我试图了解Java的BigInteger类的modPow和modInverse的行为,因为它们不像我期望的那样工作.也许我错过了一些简单的东西,所以这里有一段非常简单的代码:

BigInteger a = BigInteger.valueOf(2);
BigInteger b = BigInteger.valueOf(5);

BigInteger n1 = new BigInteger(32, 100, new SecureRandom());
System.out.println("n = " + n1);

System.out.println("a^b = " + a.modPow(b, n1) + " ;; (a^b)^(b^-1) = " + a.modPow(b, n1).modPow(b.modInverse(n1), n1));
Run Code Online (Sandbox Code Playgroud)

我得到的输出是:

n = 2664021049    (This is a random prime, can change each run)
a^b = 32 ;; (a^b)^(b^-1) = 4
Run Code Online (Sandbox Code Playgroud)

现在,我希望4最后一行的2那个就是它(a^b)^(1/b) = a^(b*(1/b)) = a

这是否也适用于模数字段?

我究竟做错了什么?

java biginteger modulo

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

使用Spring Security进行Thymeleaf授权不起作用

我在Spring Boot应用程序中使用Spring Security,似乎Thymeleaf授权无法正常工作.

我有Thymeleaf模板,代码如下:

<div class="container">
    <div class="row" sec:authorize="isAuthenticated()">
        <h2 style="color:green">User is Logged In</h2>
        <p sec:authentication="principal.username">username</p>
    </div>

    <div class="row" sec:authorize="!isAuthenticated()">
        <h2 style="color:red">User is Logged Out</h2>
    </div>

    <div class="row" sec:authorize="hasRole('ROLE_SUPERUSER')">
        <h2>This will only be displayed if authenticated user has role ROLE_SUPERUSER.</h2>
    </div>

    <div class="row" sec:authorize="hasRole('ROLE_ADMIN')">
        <h2>This will only be displayed if authenticated user has role ROLE_ADMIN.</h2>
    </div>

    <div class="row" sec:authorize="hasRole('ROLE_USER')">
        <h2>This will only be displayed if authenticated user has role ROLE_USER.</h2>
    </div>

    <div th:if="${#authorization.expression('hasRole(''ROLE_ADMIN'')')}">
        This will only be displayed if authenticated …
Run Code Online (Sandbox Code Playgroud)

java spring-security thymeleaf spring-boot

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

无法确定合适的驱动程序类别

启动应用程序时,看到以下错误:

上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.BeanCreationException:创建名称为'blockDataController'的bean时出错:注入资源依赖项失败;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'blockSummaryImpl'的bean时出错:注入资源依赖项失败;嵌套的异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建文件[D:\ YueNiuProject \ StockMarket \ yueniu-stock-data \ market-data-dao \ target \ classes \ com \中定义的名称为'prodCodeMapper'的bean时出错yueniu \ stock \ market \ data \ mapper \ block \ ProdCodeMapper.class]:通过bean属性'sqlSessionFactory'表示的不满足的依赖关系;嵌套的异常是org.springframework。beans.factory.UnsatisfiedDependencyException:创建在类路径资源[org / mybatis / spring / boot / autoconfigure / MybatisAutoConfiguration.class]中定义的名称为'sqlSessionFactory'的bean时出错:通过方法'sqlSessionFactory'参数0表示的依赖关系未满足;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建在类路径资源[org / springframework / boot / autoconfigure / jdbc / DataSourceConfiguration $ Hikari.class]中定义的名称为“ dataSource”的bean时出错:通过工厂方法进行Bean实例化失败; 嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法'dataSource'引发了异常;嵌套的异常是org.springframework.boot.autoconfigure.jdbc。

java spring intellij-idea spring-boot

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

如何在 Intellj IDEA 中提交已删除的文件更改?

我有一些文件sample_file.doc在我的 IntelliJ IDEA 中可见。

如果我sample_file.doc从本地文件夹中删除文件,它会从 IntelliJ IDEA 中消失,不允许我提交已删除的文件更改。

我想提交删除,以便删除的文件更改出现在 Git 存储库中。

请告知如何在 IntellJ IDEA 中提交已删除的文件?

git commit intellij-idea delete-file

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