如何使用MyBatis获取插入的生成密钥?我读了很多关于这个问题的网页,但我仍然被封锁,有人可以帮帮我吗?这是我的代码:
桌子:
ID_ERROR long primary key
DATE timestamp
TYPE varchar
MESSAGE varchar
SOURCE varchar
Run Code Online (Sandbox Code Playgroud)
道:
Long returnedId = 0L;
MyMapper myMapper = this.sqlSession.getMapper(MyMapper.class);
myMapper.insertRecord(returnedId, Utils.now(), t.getClass().getName(), t.getMessage(), c.getName());
return returnedId;
Run Code Online (Sandbox Code Playgroud)
mapper.java:
public void insertRecord(@Param("returnedId") Long returnedId, @Param("timestamp")Timestamp timestamp,@Param("type") String type,@Param("message") String message,@Param("source") String source);
Run Code Online (Sandbox Code Playgroud)
mapper.xml
<insert id="insertRecord" parameterType="map" useGeneratedKeys="true" keyProperty="ID_ERROR">
INSERT INTO errors (
DATE,
TYPE,
MESSAGE,
SOURCE
)
VALUES (
#{timestamp},
#{type},
#{message},
#{source}
)
<selectKey resultType="long" order="AFTER" keyProperty="returnedId">
SELECT LAST_INSERT_ID() as returnedId
</selectKey>
</insert>
Run Code Online (Sandbox Code Playgroud)
怎么了?如何获取此插入的生成密钥?谢谢!
问题是这样的:
我正在运行一个swing应用程序,在某个时刻,对话框需要插入用户名和密码并按下"ok".
我希望当用户按下"ok"时,swing应用程序按此顺序执行:
这是我在okButtonActionPerformed()中编写的代码:
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
//This class simply extends a JDialog and contains an image and a jlabel (Please wait)
final WaitDialog waitDialog = new WaitDialog(new javax.swing.JFrame(), false);
waitDialog.setVisible(true);
... //Do some operation (eventually show other JDialogs or JOptionPanes)
waitDialog.dispose()
}
Run Code Online (Sandbox Code Playgroud)
这段代码显然不起作用,因为当我在同一个线程中调用waitDialog时,它会阻塞所有代码直到我不关闭它.
所以我试着在另一个线程中运行它:
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
//This class simply extends a JDialog and contains an image and a jlabel (Please wait)
final WaitDialog waitDialog = new WaitDialog(new javax.swing.JFrame(), false);
SwingUtilities.invokeLater(new Runnable() …Run Code Online (Sandbox Code Playgroud) 如何从字符串中获取Jsoup元素?例如,如果我有一个字符串
String myDiv = "<div>Hello jsoup world</div>";
Run Code Online (Sandbox Code Playgroud)
我想在元素中转换.目前我使用Jsoup.parse(..)方法转换Document中的String,然后将该文档的主体作为Element.有直接的方法吗?
我有一组primefaces复选框(p:selectBooleanCheckbox),每个复选框都有一个定义的widgetVar( widgetVar="rowCheckbox_0" , widgetVar="rowCheckbox_1" , widgetVar="rowCheckbox_2" ,.. )。我想获得对它们的引用并使用 JQuery 检查它们,但我是新手,我不知道该怎么做。
这是我为获取复选框引用而编写的函数:
function selectAllCheckbox() {
var test = $(PrimeFaces.widgets.rowCheckbox_0);
if (test.length){
alert('Element found ');
}
else {
alert('Element NOT found');
}
}
Run Code Online (Sandbox Code Playgroud)
如果我执行代码,警报会告诉我“找到元素”,所以我想我走对了。现在我不知道如何:
1) 对元素“test”(应该指第一个复选框)执行 .check() 函数。
2)获取一个包含所有复选框引用的数组(以“rowCheckbox_”开头的“$PrimeFaces.widgets.”)任何人都可以帮助我吗?
我想创建一个存储方法引用列表的类,然后使用Java 8 Lambda执行所有这些,但是我遇到了一些问题.
这是班级
public class MethodExecutor {
//Here I want to store the method references
List<Function> listOfMethodsToExecute = new LinkedList<>();
//Add a new function to the list
public void addFunction(Function f){
if(f!=null){
listOfMethodsToExecute.add(f);
}
}
//Executes all the methods previously stored on the list
public void executeAll(){
listOfMethodsToExecute.stream().forEach((Function function) -> {
function.apply(null);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我为测试创建的类
public class Test{
public static void main(String[] args){
MethodExecutor me = new MethodExecutor();
me.addFunction(this::aMethod);
me.executeAll();
}
public void aMethod(){
System.out.println("Method executed!");
}
} …Run Code Online (Sandbox Code Playgroud) 在Java中是否可以将注释值存储在常量字段(或类似字段)中,以便在需要的每个方法上重用它?例如,如果我有这个带注释的方法:
@CustomAnnotations({
@CustomAnnotation(..),
@CustomAnnotation(..),
@CustomAnnotation(..),
@CustomAnnotation(..),
...
@CustomAnnotation(..)
})
private static MyReturnValue doSomething(){
..
}
Run Code Online (Sandbox Code Playgroud)
我想向同一个类中的许多方法添加相同的注释,而不需要为每个方法剪切和粘贴它,是否可以定义一个字段,例如:
private static final Something annotationsConstant = {
@CustomAnnotation(..),
@CustomAnnotation(..),
@CustomAnnotation(..),
@CustomAnnotation(..),
...
@CustomAnnotation(..)
}
@CustomAnnotatins(annotationsConstant)
private static MyReturnValue doSomething(){
..
}
@CustomAnnotatins(annotationsConstant)
private static MyReturnValue anotherMethod(){
..
}
Run Code Online (Sandbox Code Playgroud)
如果是,包含注释的字段的数据类型是什么?如果没有,是否有另一种方法无需为每个方法重写相同的注释?
我想在本地进行Sonar在服务器上执行的代码分析.
关于PMD,Findbugs和Checkstyle的规则我没有问题下载它们并使用适当的插件导入Netbeans.
我的问题涉及我在声纳中发现的另外两组规则,称为"JavaSonarQube"和"Java Common Sonarqube".他们指的是什么样的分析器,如何在NetBeans中导入和运行它们?