我想知道是否可以在spring数据的命名查询中使用泛型(我自己使用jpa),是否可以做这样的事情?
@NoRepositoryBean
public interface EnumerationRepository<T extends Enumeration> extends JpaRepository<T,Integer> {
@Query("Select t.type from T t")
public List<String> selectTypes();
}
Run Code Online (Sandbox Code Playgroud)
枚举类就是这个
@MappedSuperclass
public abstract class Enumeration {
@Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id", length = 3)
private int id;
@Column(name = "type", nullable = false, unique = true, length = 30)
private String type;
// getters / setters .. etc
}
Run Code Online (Sandbox Code Playgroud)
为简单起见,我在Enumeration类中省略了一些字段.
试过这个,但很明显它抱怨导致类T没有映射.
关键是因为我有20多个表共享一些基本结构,并且因为我需要查询只从列中提取数据,而不是整个实体,所以很高兴找到一种方法来获取"父"存储库中的查询而且不必复制代码20次以上.
免责声明:我知道如何使用百万富翁手动注入令牌:
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}" />`
Run Code Online (Sandbox Code Playgroud)
这篇文章的目标是提高平台的知识,并更好地了解Spring Boot中的内容
我没有尝试过Spring Boot,但最近我决定尝试一下,并且不得不承认它很棒,但是在Spring MVC上使用Thymeleaf和Security,我不需要在表单上注入CSRF令牌(POST),因为Thymeleaf会自动处理它,但现在Spring Boot因为某种原因没有.
从Spring Boot Reference中,我找到了application.properties文件中使用的常用属性的列表,与thymeleaf和security相关的属性是:
Thymeleaf Properties
spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.excluded-view-names= # comma-separated list of view names that should be excluded from resolution
spring.thymeleaf.view-names= # comma-separated list of view names that can be resolved
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html # ;charset=<encoding> is added
spring.thymeleaf.cache=true # set to false for hot refresh
Run Code Online (Sandbox Code Playgroud)
安全属性
security.user.name=user # login username
security.user.password= # login password
security.user.role=USER # role assigned to the user
security.require-ssl=false # …Run Code Online (Sandbox Code Playgroud) 我打算将我开始构建的应用程序分解为带有图形数据库的巨型组件到微服务中.但我面临的困境是试图找到一个合适的解决方案来拆分不同的服务,而不是失去图数据库提供的好处.
我最初考虑的想法是将每个不同的实体分成它自己的微服务,使用文档存储来保存每个服务上的数据.然后定义更高级别的服务来管理关系.
例如,使用关系(A) - >(B),将产生3个微服务,一个服务用于类型A的实体,另一个用于类型B的实体,第三个更高级别用于图形数据库,存储类型的节点A和B,仅包含ID和它们之间的关系.
问题1:这种方法在耦合,容错或其他任何我现在无法想到的方面有什么问题吗?
问题2:当你将第三个实体投入游戏时,例如(A) - >(B),(A) - >(C)和(C) - >(B),哪一个将是这种情况下的最佳方法?
问题3:在相同类型的实体,例如间(人)的关系的情况下- isFriendOf - >(人),铭记的关注点分离的概念,它被appropiate以分离关系的管理进入不同的服务?
任何意见,反馈和想法都非常受欢迎.
我一直在研究这个问题,为了清楚起见,我会提出一个更具体的方案,所以讨论它会更容易.图模型将是这样的:
这里的目标是实现歌曲播放列表推荐服务,试图根据用户已经听过的歌曲中的流派和艺术家以及其他人听过的其他歌曲来找到给定用户尚未收听的歌曲.用户,后跟当前用户.