小编Har*_*ana的帖子

领域层和持久层的区别

领域层和持久层是指相同还是不同。域层是我们通常映射到数据库表的DAO,对吗?那么持久层意味着相同还是更多?

如果我们将映射到数据库表的 POJO 称为 DAO,我们所说的驻留查询执行并填充这些 DAO (POJOS) 的类。

最佳做法是什么?将查询执行代码保留在那些 POJO 中还是将它们作为一个单独的类?我的意思是示例假设 A 是到数据库表 A 的类映射。我们是否需要实现像 ADaoImpl 这样的单独类来放置类 A 所需的查询相关代码?我相信这是不对的?将与所有 DAO 类相关的所有 DAO 对象填充、查询执行等保存在一个名为 RBMSDaoImpl 的单个类中,这难道不是最佳实践吗?所以我们称该类为属于 DAO 层的 out 应用程序的 DAO 实现类,对吗?

总而言之,POJOS(DAO) 和 DAOImpl 是我们应用程序的 DAO 层,对吗?持久层是..?

谢谢。

java persistence

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

使用多个提交按钮标识单击的提交按钮的值

我有这样的情况,我需要跟踪哪个提交按钮单击,以便根据该设置变量.以下是测试代码,

<script>
function submitForm(form) {
    alert(document.getElementById('sb').value);
    if (document.getElementById('sb').value=="One") {
        //Do something
    }
    return true;
}
</script>


<form action="" method="get" onsubmit="return submitForm(this);">
    <input type="submit" name="sb" value="One">
    <input type="submit" name="sb" value="Two">
    <input type="submit" name="sb" value="Three">
</form>
Run Code Online (Sandbox Code Playgroud)

即使我单击按钮Two或Three,警报也始终显示One.但是url随可点击参数而变化.如何提醒可点击提交按钮中的值?

注意:我想要一个没有JQuery的解决方案

编辑:我更改了onsubmit调用submitForm(this)的代码位; 问题是甚至使用document.forms [0] .sb.value它的undefined因为document.forms [0] .sb返回所有提交按钮的节点列表,与document.getElementById('sb')相同

javascript web-applications

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

分叉存储库中未显示上游git标记

我在上游用主分支代码推送了1.11.57标签。我正在使用bitbucket和git bash

在此处输入图片说明

我在存储库上进行了分叉,并在本地使用fork存储库作为本地主分支。但是在我的分叉存储库中,没有显示1.11.57标记。

在此处输入图片说明

我检查存储库同步也没有问题。这是什么原因,以及如何将上游标签添加到我的fork,然后再添加到本地标签。

git version-control bitbucket

5
推荐指数
2
解决办法
923
查看次数

一个spring boot应用的tomcat默认线程池

在 Spring Boot 应用程序中或一般情况下,tomcat 是否配置了默认线程池?

如果我们不配置任何东西,tomcat 会为每个请求启动新线程,一旦请求完成,线程就会被销毁?

如果配置了一个线程池,当容器从池中选择该线程时,特定线程将服务许多请求?

java multithreading tomcat threadpool spring-boot

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

AWS SDK无法读取环境变量

我正在为 Jenkins 设置 AWS_ env 变量,如下所示

    sudo apt-get update -y
    sudo apt-get install -y python3 python-pip python-devel
    sudo pip install awscli
    S3_LOGIN=$(aws sts assume-role --role-arn rolename --role-session-name s3_session)
    export AWS_CREDENTIAL_PROFILES_FILE=~/.aws/credentials
    export AWS_ACCESS_KEY_ID=$(echo ${S3_LOGIN}| jq --raw-output '.Credentials|"\(.AccessKeyId)"')
    export AWS_SECRET_ACCESS_KEY=$(echo ${S3_LOGIN} | jq --raw-output '.Credentials|"\(.SecretAccessKey)"')
    export AWS_SESSION_TOKEN=$(echo ${S3_LOGIN} | jq --raw-output '.Credentials|"\(.SessionToken)"')
    aws configure set default.region us-east-2
    aws configure set AWS_ACCESS_KEY_ID $AWS_ACCESS_KEY_ID
    aws configure set AWS_SECRET_ACCESS_KEY $AWS_SECRET_ACCESS_KEY
Run Code Online (Sandbox Code Playgroud)

但是当我尝试从代码中获取它们时,sdk 无法读取已设置的环境变量

 AWSCredentials evc = new EnvironmentVariableCredentialsProvider().getCredentials();
 AmazonS3Client amazonS3 = new AmazonS3Client(evc);
 amazonS3.setRegion(RegionUtils.getRegion("us-east-2"));
Run Code Online (Sandbox Code Playgroud)

com.amazonaws.AmazonClientException:无法从环境变量(AWS_ACCESS_KEY_ID(或 AWS_ACCESS_KEY)和 …

java amazon-s3 amazon-web-services jenkins aws-sdk

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

将@Autowired与SpringBoot中配置的过滤器一起使用

我需要在过滤器中使用自动装配.所以我使用@Component注释我的过滤器类,

import org.springframework.web.filter.GenericFilterBean;
@Component
public class TokenAuthorizationFilter extends GenericFilterBean {
    @Autowired
    public EnrollCashRepository enrollCashRepository;
}
Run Code Online (Sandbox Code Playgroud)

然后我在SecurityConfig中添加我的过滤器,如下所示

   @Configuration
    @EnableWebMvcSecurity
    public class SecurityConfig extends WebSecurityConfigurerAdapter {

        @Override
        public void configure(WebSecurity webSecurity) throws Exception
        {
            webSecurity.ignoring().antMatchers(HttpMethod.GET, "/health");
        }
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.addFilterBefore(new TokenAuthorizationFilter(), BasicAuthenticationFilter.class);  
            http.authorizeRequests().antMatchers("/api/**").authenticated();    
    }
Run Code Online (Sandbox Code Playgroud)

我的问题是我的过滤器被@Component注释调用了两次.如果我删除@Component注释,它只调用一次.

然后我在下面添加我的Spring启动主类中的修复程序.然后我在SecurityConfig中评论addFilterBefore行.

 @Bean
    public FilterRegistrationBean tokenAuthFilterRegistration() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new PITokenAuthorizationFilter());
        filterRegistrationBean.setOrder(1);
        filterRegistrationBean.setEnabled(false);
        return filterRegistrationBean;
    }
Run Code Online (Sandbox Code Playgroud)

但是我的过滤器被调用了一次.但即使我使setEnabled为true或false,当我调用我的rest api时,我得到403 Forbiddon错误,http:// localhost:8080/api/myservice

我怎样才能解决这种情况,我可以在Spring Filter中使用@Autowired?

编辑:添加控制器和Filter类,

@RestController
@RequestMapping(value = "/api")
public …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

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

使用mongodb中的日期保存TimeZone

我的文档类中有java.util.Date字段.

例如:

@Document(collection = "testdoc")
public class TestDoc {
    @Id
    String id;
    Date startDate;
}
Run Code Online (Sandbox Code Playgroud)

即使我用UTC和IST设置日期,它总是保存在我的收藏中,如下所示,

 "startDate" : ISODate("2015-08-21T18:30:00.000Z")
Run Code Online (Sandbox Code Playgroud)

如何在mongo集合中保存时区?Z在这种情况下有什么作用?

java mongodb java.util.date

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

Redis哨兵与春季启动设置

我在1个主节点和2个从节点上有redis,并且在每个服务器上,端口26379上运行着一个哨兵进程

我想知道如何将哨兵配置为主,以便在application.property文件中添加以下内容。

spring.redis.sentinel.master=
spring.redis.sentinel.nodes=
Run Code Online (Sandbox Code Playgroud)

我有Redis服务器2.8.19和Spring Boot 1.3.4,spring-data-redis 1.6.4 jars

java spring redis node.js spring-boot

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

如何使用aws s3 cp复制根目录中的所有对象而不复制子目录?

我需要将AWS S3存储桶根文件夹中的内容复制到root中的另一个文件夹.

我想将root(textfile1.txt等)中的所有文件复制到folder3中,除了其他文件夹(folder1,folder2).

什么是aws s3复制命令呢?

/
folder1
folder2
textfile1.txt
textfile2.txt
--many other text files
folder3
Run Code Online (Sandbox Code Playgroud)

amazon-s3 amazon-ec2 amazon-web-services

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

使用 Spring 数据 MongoRepository 更新查询的自定义方法

我正在使用 org.springframework.data.mongodb.repository.MongoRepository。我写了一些像下面这样的自定义方法,

public interface DocRepository extends MongoRepository<Doc, String> {
     Doc findByDocIdAndAssignmentId(final String docId, final String assignemtId);
}
Run Code Online (Sandbox Code Playgroud)

如何编写自定义方法,在满足条件时更新所有条目。

例如,如果分配 ID 为“xyz”,则将文档倾斜字段设置为“abc”?

java mongodb spring-data mongorepository spring-boot

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