我想用新的实体值增量更新列值,例如:
支持我有一个表 USER,其列名称为 BALANCE
对于特定用户,他的余额是3000。
现在,我想将他的值设置为3500。
我有一个休眠“用户”实体,其“余额”值为 500。
我怎样才能进行更新?
如果我想使用纯 sql 查询来实现它,我会简单地执行以下操作:
“更新用户设置余额=余额+500,其中user_id=3”
我想避免调用 sql 并使用 hibernate。
我正在尝试使用hibernate进行简单的SQL UPDATE查询,并将结果行映射到Hibernate实体(使用createSQLQuery)。
String updateQuery =
String.format("UPDATE \"user\" "
+ "SET chips_balance=chips_balance + %d, diamonds_balance=diamonds_balance + %d "
+ "WHERE id=%d", chips_delta, diamonds_delta, userId);
User user = (User)session.createSQLQuery(updateQuery).uniqueResult();
Run Code Online (Sandbox Code Playgroud)
这将引发异常:
org.hibernate.exception.GenericJDBCException: could not extract ResultSet
Run Code Online (Sandbox Code Playgroud)
原因:
org.postgresql.util.PSQLException: No results were returned by the query.
Run Code Online (Sandbox Code Playgroud)
我该如何进行这项工作?(使用RETURNING关键字)
我已使用 IntelliJ 2021 升级到最新的 Checkstyle 插件 (8.41.1)。我正在尝试配置自定义 google checkstyle xml 文件,因此我从Github获取了最新的示例,并尝试将其设置为 checkstyle 插件的配置文件但我收到以下异常
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module TreeWalker - cannot initialize module JavadocMethod - Property 'accessModifiers' does not exist, please check the documentation
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:473)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:201)
at org.infernus.idea.checkstyle.service.cmd.OpCreateChecker.execute(OpCreateChecker.java:61)
...
...
Run Code Online (Sandbox Code Playgroud)
如果我设置内置的 Google 检查,那么它就可以工作。
任何想法?
我有一个类型的对象:Optional<String>我想在运行时知道什么是泛型类型Optional- 意思是'字符串'.
我试过了:
obj.getClass()
Run Code Online (Sandbox Code Playgroud)
但这会回来 java.util.Optional
然后我试过,
obj.getParameterizedType();
Run Code Online (Sandbox Code Playgroud)
但这并没有返回它有Class <>对象.
任何的想法??
我想创建一个函数来获取Class的参数并返回T的实例,
所以我有这个签名:
public <T> T foo(Class<T> clazz) {}
Run Code Online (Sandbox Code Playgroud)
现在,假设我想限制Class<T>并仅接受<T extends Command>,所以我尝试了这个:
public <T> T foo(Class<T extends Command> clazz) {}
Run Code Online (Sandbox Code Playgroud)
但是,我的班级Command也是模板如下:Command<S extends ModuleContex>
所以我试试这个:
public <T> T foo(Class<T extends Command<S extends ModuleContext>> clazz) {}
Run Code Online (Sandbox Code Playgroud)
但这不编译!
如何正确写?
我正在尝试将js脚本添加到我打开的弹出窗口中但是却无法这样做.
这是我的代码:
function openGame() {
gameWindow = window.open("", "gameWindow", "top=500, left=500, height=988, width=1263");
gameWindow.document.write('<html><head>')
gameWindow.document.write('<link rel=\"stylesheet\" href=\"cssbutton.css\">')
gameWindow.document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"sbg_style.css\">')
}
// at this point I would like to add the following script
$(document).ready(function(){
$("#checker0").click(function(){
$("div").animate({left: '250px', top:'250px'});
});
});
Run Code Online (Sandbox Code Playgroud)
这该怎么做?
我使用 SpringBoot 2.2.2.RELEASE (相当旧的版本),我有以下要求:
我有一个 @Service 类,我想通过添加接口来扩展其构造函数。当应用程序加载时,我希望基于我在属性文件中定义的某些属性,正确的接口实例是 @Autowired 。所以这基本上是一个工厂,它通过属性文件中定义的某些属性来实例化类。
这是我想象它如何工作的一个片段:
@Service
class MyService {
@Autowired
public MyService(Shape shape) { ...}
}
interface Shape { ...}
class Circle implements Shape { ... }
class Rectangle implements Shape { ... }
Run Code Online (Sandbox Code Playgroud)
魔力应该存在于某个 Factory 类中,该类从属性文件中读取属性并相应地实例化Shape.
该应用程序的每个实例都在专用计算机 (EC2) 上运行,并具有自己独特的属性文件。
Spring Boot 中是否内置了类似的东西?
任何建议,将不胜感激!
我有以下课程:
public class IntegerKey extends Number implements Comparable<IntegerKey> {
private Integer m_key;
public IntegerKey(Integer key) {
m_key = key;
}
public IntegerKey(int key) {
m_key = key;
}
}
Run Code Online (Sandbox Code Playgroud)
我想使用这个课程如下:
假设我有以下泛型:
Map<IntegerKey, MyCache> map = new HashMap<IntegerKey, MyCache>();
map.put(5, new MyCache());
Run Code Online (Sandbox Code Playgroud)
这不编译,为什么?我不想这样做:
map.put(new IntegerKey(5), new MyCache());
Run Code Online (Sandbox Code Playgroud)
谢谢.
java ×5
hibernate ×2
autoboxing ×1
boxing ×1
checkstyle ×1
html ×1
java-8 ×1
javascript ×1
postgresql ×1
reflection ×1
spring ×1
spring-boot ×1