我正致力于使用Spring 3和Hibernate 3.6开发Web应用程序.目前我试图了解如何使用Spring和Hibernate进行缓存.我找到了一些关于使用Hibernate缓存的消息来源以及一些关于Spring的消息,我现在尝试将我的信息结合在一起.我仍然对这两个框架都有一些问题,如果有人能够回答它们或告诉我这里列出的事实是否正确,我会很高兴.
大多数时候,简短的答案(是/否)就足够了.我认为这个列表对其他人也很有用,他们想要了解spring和hibernate的缓存是如何工作的.
General
1) Hibernate支持以下缓存:第一级缓存,第二级缓存,查询缓存
2) Spring本身支持以下缓存可能性:只是方法缓存
1st Level Cache
3)第一级缓存是每个Hibernate应用程序的一部分.
4)为每个休眠会话创建第一级缓存.
5)第一级缓存中保存了什么?对象或只是其属性的值?查询及其结果?
2nd Level Cache
6)我发现:每个应用程序使用ONCE二级缓存.那不是假的吗?是不是每次sessionfactory使用ONCE?和:多个sessionfactorys =多个第二级缓存可能吗?
7)在二级缓存中保存的内容:在我看来,只是属于一条记录的值,而不是对象本身.
8)当存储来自二级缓存中的一个记录的值时,它是否可以存储相关值(来自通过外键连接的对象)?
9)更新二级缓存中一个对象的值时,是否可以更新缓存中与其连接的对象的值?
10)当一个对象的值发生变化时,如何更新二级缓存?冲洗?我可以只更新缓存的一部分,还是必须更新整个缓存?
11)二级缓存在哪里有意义,哪里不存在?
12)缓存模式:每个缓存模式都提供不同的缓存策略吗?例如,对于缓存模式"只读",不需要同步数据库和缓存吗?其他缓存模式是否提供同步?我认为同步必须由开发者自己完成?
SessionFactory
13)查询缓存和二级缓存有什么区别?在我看来:在查询缓存中,结果集被保存,但没有使用它们的值,只有它们的ID.当再次使用查询并且结果集仍然"正确"时,将从二级缓存中查询属于id的值
14)对于查询缓存,必须使用二级缓存?
15)查询缓存哪里有意义,哪里不存在?
Query Cache
16) Spring是否提供了比方法缓存更多的缓存可能性?
17)方法缓存没有与hibernate缓存相关联
18)但是:对于方法缓存,第二级是必要的,比如ehcache(也可以被hibernate使用)
19)可以在没有数据库查询的情况下使用方法缓存吗?
Spring
20)如果使用ehcache作为二级缓存的hibernate和用于方法缓存的spring的ehcache,我可以使用相同的ehcache-instance吗?是否有可能混淆了什么?
21)当使用第一级缓存和第二级缓存时,它们会混淆吗?在查询数据库时,结果来自哪里,第一级或第二级缓存?第一级缓存是否与二级缓存一起使用?
22)其他任何可以通过使用我提到的缓存混淆的东西?:-)
谢谢你的回答,不管是什么问题!:-)
我正在使用Jasper报告5.2,iReport 5.2并以RTF和PDF格式导出报告.
在我的报告中,我想添加几个文本字段以及水平对齐的(静态文本)标签
Name: $F{name}
Age: $F{age}
Date of Birth: $F{dateOfBirth}
Run Code Online (Sandbox Code Playgroud)
但是我无法调整它们.这是我试过的
图像显示了我得到的和我想要的东西.此外,我的文本字段的内容是动态的,即内容大小可能会有所不同.

我已经阅读了很多论坛但找不到解决方案,请提出建议.
谢谢
我们的应用程序通常通过Web服务,MQ,JDBC,专有(直接通过套接字)和其他传输孩子连接到不同的后端之王.我们已经有许多实现允许我们从应用程序连接到这些后端,虽然所有这些实现都实现了公共java接口,但它们不共享任何其他内容.
我们已经意识到所有这些特定连接器实现都有共同的代码部分代码,我们决定通过一个通用连接器简化未来连接器的开发.此连接器将能够将消息格式化为后端预期的格式,并使用可用的传输机制发送它们.例如:MQ或超过套接字的固定长度消息格式.
我们面临的困境之一是这种连接器最合适的技术.到目前为止,我们的连接器是实现常见Java接口的基本java类.由于我们通常在某些Java EE应用程序服务器中托管我们的应用程序,因此Java Connector Architecture似乎是最适合此软件的技术.但是,实现符合JCA标准的连接器似乎相对复杂.采用标准有什么明显的好处 - JCA并且有益于额外的努力吗?
我正在尝试构建messanger应用程序.
我要从MessageResource调用CommentResource.
我想要单独的MessageResources和CommentResources.
我正在做这样的事情:
MessageResource.java
@RestController
@RequestMapping("/messages")
public class MessageResource {
MessageService messageService = new MessageService();
@RequestMapping(value = "/{messageId}/comments")
public CommentResource getCommentResource() {
return new CommentResource();
}
}
Run Code Online (Sandbox Code Playgroud)
CommentResource.java
@RestController
@RequestMapping("/")
public class CommentResource {
private CommentService commentService = new CommentService();
@RequestMapping(method = RequestMethod.GET, value="/abc")
public String test2() {
return "this is test comment";
}
}
Run Code Online (Sandbox Code Playgroud)
我想要
HTTP://本地主机:8080 /消息/ 1 /评论/ ABC
返回"这是测试评论".
任何的想法??
PS:简单来说,我想知道JAX-RS sub-resource相应的实现spring-rest
我想要做的是使用html fileupload控件选择图像,使用jcrop裁剪选择,在客户端裁剪图像并上传图像.这里是小提琴链接https://jsfiddle.net/govi20/spmc7ymp/
Id用于代码: jcrop图像的
目标
图片 fileupload控件
预览画布预览
clear_selection按钮清除所选区域
设置jcrop.
<script src="./js/jquery.min.js"></script>
<script src="./js/jquery.Jcrop.js"></script>
<script src="./js/jquery.color.js"></script>
Run Code Online (Sandbox Code Playgroud)
清除选择.
<script type="text/javascript">
jQuery(function($){
var api;
$('#target').Jcrop({
// start off with jcrop-light class
bgOpacity: 0.5,
keySupport: false,
bgColor: 'black',
minSize:[240,320],
maxSize:[480,640],
onChange : updatePreview,
onSelect : updatePreview,
height:160,
width:120,
addClass: 'jcrop-normal'
},function(){
api = this;
api.setSelect([0,0,240,320]);
api.setOptions({ bgFade: true });
api.ui.selection.addClass('jcrop-selection');
});
});
Run Code Online (Sandbox Code Playgroud)
在jcrop中显示上传的文件
jQuery('#clear_selection').click(function(){
$('#target').Jcrop({
setSelect: [0,0,0,0],
});
});
Run Code Online (Sandbox Code Playgroud)
裁剪图像并将其分配给画布(从stackoverflow上的一个线程获取此图像)
function readURL(input) {
if (input.files && input.files[0]) {
var reader …Run Code Online (Sandbox Code Playgroud) 我正在使用jquery ajax方法尝试fileupload.但是它导致客户端415(不支持的媒体类型)错误.但是使用非ajax请求我的代码工作正常.
我的控制器代码.
@RequestMapping(value = "/imageUpload", headers = "content-type=multipart/*", method = RequestMethod.POST, consumes = "application/json")
public @ResponseBody
String uploadImage( @RequestParam("fileData") MultipartFile multipartFile, HttpServletRequest request )
{
// statements
}
Run Code Online (Sandbox Code Playgroud)
我的观点页面
<form id="uploadForm" action="imageUpload" method="post" enctype="multipart/form-data">
<div>
<input type="file" id="fileData" name="fileData" />
<input type="submit" id="submitContent" value="upload" />
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
和ajax电话.
$("#uploadForm").submit(function (e) {
e.preventDefault();
var $form = $("#uploadForm");
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
dataType : 'json',
enctype: 'multipart/form-data',
processData: false,
success: function(msg){
$( "#editor" ).append(msg);
},
error: function(XMLHttpRequest, textStatus, …Run Code Online (Sandbox Code Playgroud) 我有条件要求我获取适用于某些课程的费用.但问题是,对于很少的课程,相同的费用适用于所有类型的用户,对于某些课程,适用专业费用.例如,如果用户是教师,那么他的费用与他是行业专业人员的费用不同.
数据库中有预定义的职业.
这是我当前的代码逻辑.
根据单选按钮,我在后端切换正确的div和特定逻辑.
<input type="radio" name="professionWiseFees" value="true">
<input type="radio" name="professionWiseFees" value="false">
<div id="totalAmount" class="hidden">
<input class="feeAmountOnly" name="feeAmount" type="text" />
</div>
<div id="professionWiseAmount" class="hidden">
<c:forEach items="${applicationScope.professionList}" var = "profession" >
Course Fee For ${profession.profession}
<input type="hidden" value="${profession.id}" name="profession" type="text"/>
<input class="feeAmoun2t" name="profession" type="text" />
</c:forEach>
<div>
Run Code Online (Sandbox Code Playgroud)
现在我正在检查适用的费用类型并根据它填写hashmap.如果prefessionWiseFees不适用,则向所有专业添加相同的费用.
Boolean isProfessionWiseFeesApplicable = Boolean.parseBoolean(reqParams.get("professionWiseFees")[0]);
Map<Integer,Double> feeProfessionMap = new HashMap<>();
List<Profession> professions = (List<Profession>) servletContext.getAttribute("professionList");
if(isProfessionWiseFeesApplicable) {
String[] propfessionWiseFees = reqParams.get("profession");
// [1(profession_id),1000(fees),2,2000,3,7000], hence i+2 i=profession_id, i+1=fees
for(int i=0; i < propfessionWiseFees.length-1 ;i=i+2){
feeProfessionMap.put(Integer.valueOf(propfessionWiseFees[i]),Double.parseDouble(propfessionWiseFees[i+1])); …Run Code Online (Sandbox Code Playgroud) 我创建一个Map<String,String>从List<Person>使用Java的8个流
persons.stream()
.collect(Collectors.toMap(Person::getNationality, Person::getName, (name1, name2) -> name1)
Run Code Online (Sandbox Code Playgroud)
但是在以上情况下,我想通过使用人的年龄来解决名字冲突。有什么办法可以绕过传递合并功能(age1, age2) -> // if age1 is greater than age2 return name1, else return name2吗?
我正在尝试构建一个 Java Spring Boot 应用程序,该应用程序可以发布和获取来自 Confluent Cloud Kafka 的消息。
我按照将Kafka 消息发布到 Confluent Cloud的文章进行操作,并且它有效。
下面是实现
卡夫卡控制器.java
package com.seroter.confluentboot.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.seroter.confluentboot.dto.Product;
import com.seroter.confluentboot.engine.Producer;
@RestController
@RequestMapping(value = "/kafka")
public class KafkaController {
private final Producer producer;
private final com.seroter.confluentboot.engine.Consumer consumer;
@Autowired
KafkaController(Producer producer,com.seroter.confluentboot.engine.Consumer consumer) {
this.producer = producer;
this.consumer=consumer;
}
@PostMapping(value = "/publish")
public void sendMessageToKafkaTopic(@RequestParam("message") String message) {
this.producer.sendMessage(message);
}
@PostMapping(value="/publishJson")
public ResponseEntity<Product> publishJsonMessage(@RequestBody …Run Code Online (Sandbox Code Playgroud) 在我的代码中,我正在检查用户学位是否完整,
这是我到目前为止所尝试过的,
$("input:radio[name=isDegreeComplete]").change(function() {
var isDegreeCompleted = $('input:radio[name=isDegreeComplete]:checked').val();
if (isDegreeCompleted == 'true') {
$('#yearOfQualifyingDegree option:gt(2016)').remove();
}
else
{
$('#yearOfQualifyingDegree option[value<2016 && value>-1]').remove();
}
});
Run Code Online (Sandbox Code Playgroud)
我努力了,
$('#yearOfQualifyingDegree option[value>2016]').remove();
Run Code Online (Sandbox Code Playgroud)
但这也行不通。那么其中缺少什么吗?
PS:我使用的是JQuery1.11.0
java ×5
jquery ×3
spring ×3
spring-mvc ×3
javascript ×2
spring-boot ×2
ajax ×1
alignment ×1
apache-kafka ×1
backend ×1
caching ×1
connector ×1
css ×1
ehcache ×1
hibernate ×1
image ×1
ireport ×1
java-8 ×1
java-ee ×1
java-stream ×1
jca ×1
jcrop ×1
rest ×1
textfield ×1