这是我的代码中的一个例子:
基类:
abstract class AbstractBase implements Comparable<AbstractBase> {
private int a;
private int b;
public int compareTo(AbstractBase other) {
// compare using a and b
}
}
Run Code Online (Sandbox Code Playgroud)
执行:
class Impl extends AbstractBase {
private int c;
public int compareTo(Impl other) {
// compare using a, b and c with c having higher impact than b in AbstractBase
}
Run Code Online (Sandbox Code Playgroud)
FindBugs将此报告为一个问题.但那是为什么呢?怎么会发生什么?
我将如何正确实施解决方案?
如何将字符串转换为哈希映射
String value = "{first_name = naresh, last_name = kumar, gender = male}"
Run Code Online (Sandbox Code Playgroud)
成
Map<Object, Object> = {
first_name = naresh,
last_name = kumar,
gender = male
}
Run Code Online (Sandbox Code Playgroud)
关键是String和价值观HashMap
注意:键可以是任何类似的东西 first_name
任何通用的方法将不胜感激.
在我的SQL中,我使用WHERE和LIKE子句来执行搜索.但是,我需要对两列的组合值执行搜索 - first_name并且last_name:
WHERE customers.first_name + customers.last_name LIKE '%John Smith%'
这不起作用,但我想知道如何沿着这些方向做点什么?
我试图通过两列分开搜索,如下所示:
WHERE customers.first_name LIKE '%John Smith%' OR customers.last_name LIKE '%John Smith%'
但显然这不起作用,因为搜索查询是这两列的组合值.
我想知道如何跨类使用synchronized块.我的意思是,我想在多个类中同步块,但它们都在同一个对象上进行同步.我想到如何做到这一点的唯一方法是这样的:
//class 1
public static Object obj = new Object();
someMethod(){
synchronized(obj){
//code
}
}
//class 2
someMethod(){
synchronized(firstClass.obj){
//code
}
}
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我创建了一个在第一个类中同步的任意Object,在第二个类中也通过静态引用它来同步它.但是,这对我来说似乎很糟糕.有没有更好的方法来实现这一目标?
我使用以下查询与MySQL 5.5(或以前的版本)多年没有任何问题:
SELECT t2.Code from (select Country.Code from Country order by Country.Code desc ) AS t2;
Run Code Online (Sandbox Code Playgroud)
结果的顺序总是在我需要的时候下降.
上周,我刚刚迁移到一个新的MySQL版本(事实上,我已迁移到MariaDB 10.0.14),现在使用相同数据库的相同查询不再按降序排序.它按升序排序(或使用自然顺序排序,实际上不确定).
那么,有人可以告诉我这是一个错误还是这是对MySQL/MariaDB最新版本中行为的改变?
谢谢.
G.普兰特
我在Spring服务中存在持久性问题.休息控制器R接收请求,并通过一些代码层以复杂的方式调用服务S. S中的服务方法声明一个事务; 这应该是第一次启动交易.但是服务的行为就像之前已经启动的事务一样,并且我的一些数据对象将成为会话的一部分(他们不能这样做).如何确定交易是否已处于活动状态?我试图注入EntityManager和/或JpaTransactionManager; 但两者似乎没有任何帮助.
如何检查我是否在交易中?
在我寻找可能的嫌疑人的所有这些层次之前,我想确定这一点.
在Eclipse中我的Maven控制的java项目中工作期间,有时会将奇怪的依赖项添加到项目的pom.xml中(scala.lang或其他).通常我在将更改提交到源存储库时会意识到这一点(有时我没有意识到).
我使用基于Kepler 4.3.2的Spring Source Tool Suite 3.5.1,从Sonatype安装了Maven Integration for AJDT.
当Eclipse自动确定源文件中的导入时,可能会有一些自动化,它会将依赖项添加到pom.xml中.我可以禁用这种不受欢迎的行为吗?
我需要根据特定的索引范围对String的ArrayList进行排序.例如,我在列表中有以下项目:["abc", "xyz", "pqr" , "asd"]现在我想从索引1到最后一个索引对此列表进行排序.
一种方式因为我认为我可以从主列表创建具有所需索引范围的子列表,对其进行排序并相应地添加子列表.但我的问题是,有没有可用的API?或任何其他更快的方式来实现这一目标.
问候,
阿南德
我有一个关于java和并发的问题.
假设我有一个名为a的ThreadLocal变量.我使用CachedThreadPool来获取新线程.当一个线程被重新调用时,ThreadLocal变量会发生什么?它保持相同的值(因为它是一个相同的线程)或它开始为空(好像线程是新的)?
谢谢
我遇到了此代码的问题:
@ExtendWith(MockitoExtension.class)
class ApiRestControllerTest {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private MockMvc mockMvc;
@InjectMocks
private ApiRestController apiRestController;
@BeforeEach
void setUp() {
mockMvc = MockMvcBuilders
.standaloneSetup(apiRestController)
.build();
}
@Test
void shouldReturnsVersion() throws Exception {
mockMvc.perform(get("/api/v1/version"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(content().json(OBJECT_MAPPER.writeValueAsString(new VersionResponse(VERSION))));
}
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
@ExtendWith(MockitoExtension.class)
class ApiRestControllerTest {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private MockMvc mockMvc;
@InjectMocks
private ApiRestController apiRestController;
@BeforeEach
void setUp() {
mockMvc = MockMvcBuilders
.standaloneSetup(apiRestController)
.build();
}
@Test
void shouldReturnsVersion() throws Exception {
mockMvc.perform(get("/api/v1/version")) …Run Code Online (Sandbox Code Playgroud) java ×8
mysql ×2
sql ×2
arraylist ×1
collections ×1
concurrency ×1
eclipse ×1
findbugs ×1
hashmap ×1
junit5 ×1
mariadb ×1
maven ×1
sorting ×1
spring ×1
spring-mvc ×1
spring-test ×1
sql-order-by ×1
subquery ×1
thread-local ×1
threadpool ×1
transactions ×1