我需要在休眠状态下禁用 ONLY_FULL_GROUP_BY。这是我当前的会话工厂。我不确定如何在此指定 sql_mode=''。
<bean id="eAgilitySessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="eAgilitysDataSource"/>
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${mysql.dialect}</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.connection.useUnicode">true</prop>
<prop key="hibernate.connection.characterEncoding">UTF-8</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
<prop key="hibernate.connection.url">${dwh.db.url}</prop>
<prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
</props>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud) 今天我接受了一次采访,我被要求对此进行编码..你已经创建了一个无序的二叉树,任何节点都没有数据.我们有一个具有相同数量元素的数组.我们必须在二叉树中插入数据作为二叉搜索树而不改变二叉树的结构.
我想出的方法是对数组进行排序,然后逐个遍历其元素,将每个数据元素放在树中的第一个空的inorder节点中.但我猜这是不正确的,因为我没有被选中.
很抱歉,如果不允许算术问题.如果有这样的问题我会把它拿下来......
我在代码中找到了这一行
List<Element> elements = Arrays.asList(element);
Run Code Online (Sandbox Code Playgroud)
并发现奇怪的是我们只需要在一个元素上使用 Arrays.asList() 。这让我开始思考是否有一种更好的方法来初始化仅包含一个元素的 ArrayList 而不使其不可变。据我所知,ArrayList 没有只接受一个元素的构造函数。
编辑-根据 Aomine 的回答,我发现这是目前做我需要做的事情的唯一方法
List<Element> elements = Stream.of(element).collect(Collectors.toCollection(ArrayList::new));
Run Code Online (Sandbox Code Playgroud) 我正在尝试模拟这个使用 rest 模板调用 API 并返回一个列表的服务。
我无法模拟该restTemplate.exchange()方法。它给了我一个“java.lang.IllegalArgumentException:URI 不是绝对的”异常。
编辑-我愚蠢的自己忘记在测试用例中将 http:// 放在基本 url 之前,这就是我得到它的原因。感谢您的帮助并为浪费您的时间道歉。
测试方法
@Value("${base-url}")
private String baseUrl;
@Override
public List<Currency> getCurrencyList() {
RestTemplate restTemplate = new RestTemplate();
String url = baseUrl + "/currency";
ResponseEntity<List<Currency>> result;
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> dataHttpEntity = new HttpEntity<>(headers);
log.info(url);
result = restTemplate.exchange(url, HttpMethod.GET,dataHttpEntity, new ParameterizedTypeReference<List<Currency>>() {
});
return result.getBody();
}
Run Code Online (Sandbox Code Playgroud)
测试代码
@Test
public void getCurrencyListTest() {
ResponseEntity<List<Currency>> result = ResponseEntity.ok(currencyList);
when(restTemplate.exchange( ArgumentMatchers.anyString(),
ArgumentMatchers.any(HttpMethod.class),
ArgumentMatchers.any(),
ArgumentMatchers.<Class<List<Currency>>>any())).thenReturn(result);
assertEquals(currencyList,service.getCurrencyList());
}
Run Code Online (Sandbox Code Playgroud)
例外
java.lang.IllegalArgumentException: URI …Run Code Online (Sandbox Code Playgroud) 我有这个代码,像往常一样,变量"local"的值保持不变,因为它是一个const.
const int local = 10;
int *ptr = (int*)&local;
printf("Initial value of local : %d \n", local);
*ptr = 100;
printf("Modified value of local: %d \n", local);
Run Code Online (Sandbox Code Playgroud)
虽然,当我将local设置为const volatile时,它会将local的值更改为100.为什么?
const volatile int local = 10;
int *ptr = (int*)&local;
printf("Initial value of local : %d \n", local);
*ptr = 100;
printf("Modified value of local: %d \n", local);
Run Code Online (Sandbox Code Playgroud)
我理解的volatile的唯一含义是它阻止编译器对该变量进行优化,以防它的值必须由外部元素更改.但我无法弄清楚如何以及为什么volatile会覆盖const的功能.
编辑 - 从所有答案看来,我的代码是模糊的,任何输出都是不可预测的,因为我正在调用未定义的行为.
java ×4
algorithm ×1
apache-poi ×1
binary-tree ×1
c++ ×1
const ×1
excel ×1
group-by ×1
hibernate ×1
mockito ×1
mysql ×1
pointers ×1
resttemplate ×1
volatile ×1