我有一个 MyBatis 查询,如下所示:
<if test="userIdList != null and userIdList > 0">
AND galleries.id IN (
SELECT gallery_id
FROM gallery_users
WHERE gallery_id IN (
<foreach collection="userIdList" item="item" separator="," open="(" close=")">
#{item}
</foreach>
)
GROUP BY gallery_id HAVING COUNT(gallery_id) = ???
)
</if>
Run Code Online (Sandbox Code Playgroud)
我所坚持的部分是获取动态的集合大小。那么我怎样才能获得集合大小,以便我可以正确填写“???” 价值?
据我所知,MyBatis 和 jOOQ 用于类似的情况。所以我想知道什么时候应该在 Spring 应用程序中使用 jOOQ 而不是 MyBatis,以及每个库和框架在开发时带来的技术优缺点。
如果有人已经熟练使用 MyBatis 这样的框架编写 SQL 查询,那么切换到 jOOQ 会给他们带来什么技术优势(查询运行时、编译时错误)?
将 Alfresco form 版本 5.2 升级到版本 6.2 后,它变得不稳定:有时我们会得到:
org.mybatis.spring.MyBatisSystemException: nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: Error instantiating class java.util.ArrayList with invalid types () or values
Run Code Online (Sandbox Code Playgroud)
通常在 .parallel() 期间。集合执行。有完整的堆栈跟踪https://pastebin.com/7d7NBwkn并且有代码https://pastebin.com/RyPt5d0g。其实我连控制流程都看不懂,为什么要涉及到MyBatis呢?
请帮我!
谢谢你!
PS:实际上这个错误的重现性并不好。当我删除 .parallel() 时,不会出现此异常。并使用单线程流处理。
UPD:以下代码在 .parallel() 的情况下会引发异常。执行并且在串行执行的情况下不会引发异常:
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission("accessDeclaredMembers"));
}
Run Code Online (Sandbox Code Playgroud)
UPD 2 解决方案:在 Alfresco 版本 5.2 System.getSecurityManager() == NULL (!!!) 但在版本 6.2 中。它已被设置。这是不同行为的问题(详细信息请参见https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/ForkJoinPool.html)。V 6.2 设置 SecurityManager 和 v 5.2。没有。解决方案是将 Dockerfile 中的 …
目前我遇到了一个问题,我一直在进行大量搜索,但仍未找到答案。
问题的背景:我们在一个 URL 上有多个 DB 模式,包括模式的测试副本(例如,schema1、schema2、schema1_test、schema2_test 都在同一个 URL)。我正在尝试通过属性文件使每个架构的哪个版本使用可配置。
我们正在使用 Spring 和 mybatis,不幸的是我对这两个都是新手(所以请原谅我的无知或我在描述问题时犯的任何错误!)
所以在我的 spring 配置文件中,它存储在 /src/main/resources 下,我有以下片段:(我只添加了“configLocation”属性,后来添加了“sqlSessionFactoryBeanName”属性)
<!-- define the SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="com.example.domain" />
<property name="configLocation" value="classpath:mybatisConfig.xml" />
</bean>
<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.example.something.persistence" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
Run Code Online (Sandbox Code Playgroud)
我的mybatisConfig.xml(存放在/src/main/resources下,应该在类路径下)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<properties resource="sqlmapconfig.properties" />
</configuration>
Run Code Online (Sandbox Code Playgroud)
sqlmapconfig.properties(在同一文件夹中)
schema1=schema1_test
Run Code Online (Sandbox Code Playgroud)
我尝试在 …
我想使用动态sql语句,仅当变量不为null且大于零时才执行.像这样:
<isNotNull prepend="AND" property="ProprietaryId">
<isGreaterThan prepend="AND" property="ProprietaryId" compareValue="0">
G.PROPRIETARY_ID = #ProprietaryId#
</isGreaterThan>
</isNotNull>
Run Code Online (Sandbox Code Playgroud)
但没有预先加两个'AND'.
我已经阅读了文档,但没有找到好的例子.
请问这个设置有什么明显的错误吗?在应用程序启动时,我得到属性“命名空间”必须为元素类型“映射器”声明,当它明确声明时。
spring xml资源dao.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jms="http://www.springframework.org/schema/jms"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-2.5.xsd">
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/JNDINAME"/>
<property name="lookupOnStartup" value="true"/>
<property name="cache" value="true"/>
<property name="proxyInterface" value="javax.sql.DataSource"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.mycompany.dao"/>
<property name="sqlSessionFactory" ref="sqlSessionFactory"/>
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
界面:
public interface MyDAO {
public void save(@Param("id") String id);
}
Run Code Online (Sandbox Code Playgroud)
映射器xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<mapper namespace="com.mycompany.dao">
<typeAlias alias="xxxVO" …Run Code Online (Sandbox Code Playgroud) 我的主要功能类:
public class Database2Redis
{
public static void test(ApplicationContext applicationContext)
{
BaseFckImpl service = applicationContext.getBean(BaseFckImpl.class);
// ...
}
public static void main(String[] args) throws Exception
{
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-config.xml");
test(applicationContext);
}
}
Run Code Online (Sandbox Code Playgroud)
我的BaseFck类:
@Service
public interface BaseFck
{
@Transactional
void test();
}
Run Code Online (Sandbox Code Playgroud)
我的BaseFckImpl类:
@Service
public class BaseFckImpl implements BaseFck
{
@Transactional
public void test()
{
Log.debug("------test---------");
}
}
Run Code Online (Sandbox Code Playgroud)
我的spring-config.xml的一部分
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop …Run Code Online (Sandbox Code Playgroud) 我试图检查日期是否在start_date和end_date之间,但这不起作用:
SELECT * FROM table_foo
WHERE start_date BEFORE '2015-02-21T00:00:00' AND
end_date AFTER '2015-02-21T00:00:00';
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
谢谢
更新:
我可以使用NOW()而不是'2015-02-21T00:00:00'吗?
我使用Spring 4和MyBatis 3,想确认log4j打印sql日志,例如连接,选择,插入,更新,删除,声明,preparedStatement,resultSet到日志文件。
我的log4j.properties如下:
### set log levels ###
log4j.rootLogger=debug, stdout, log, index, D, I, W, E
#log4j.rootLogger = debug,error, log, index, D, I, W, E
log4j.FilePath=${catalina.home}/app_log
### print log to console ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %d %p [%c] - <%m>%n
### print log to console ###
log4j.appender.error = org.apache.log4j.ConsoleAppender
log4j.appender.error.Target = System.out
log4j.appender.error.layout = org.apache.log4j.PatternLayout
log4j.appender.error.layout.ConversionPattern = %d %p [%c] - <%m>%n
### create log to file ###
log4j.appender.log = org.apache.log4j.DailyRollingFileAppender …Run Code Online (Sandbox Code Playgroud) 我试图在由 IN 子句组成的 SELECT QUERY 中传递多个值。我想使用 mybatis 执行以下查询:
SELECT * FROM DBA_COMPARISON_ROW_DIF WHERE SCAN_ID in (#{childScanIDs})
Run Code Online (Sandbox Code Playgroud)
其中childScanIDs变量由多个逗号分隔的值组成。我将这些值作为由逗号分隔的所有值组成的字符串传递。下面是映射器接口中使用的方法。
@Select(getDifferencesByScanIDs)
@Results({
@Result(property="owner", column="OWNER"),
@Result(property="comparisonName", column="COMPARISON_NAME"),
@Result(property="scanID", column="SCAN_ID"),
@Result(property="localRowID", column="LOCAL_ROWID"),
@Result(property="remoteRowID", column="REMOTE_ROWID"),
@Result(property="indexValue", column="INDEX_VALUE"),
@Result(property="status", column="STATUS"),
@Result(property="lastUpdateTime", column="LAST_UPDATE_TIME")
})
List<Difference> getDifferencesByScanIDs(@Param("childScanIDs") String childScanIDs);
Run Code Online (Sandbox Code Playgroud)
我正在以这种方式构造值字符串:
String scanIDs = StringUtils.join(cmp.getChildScanIDs(), ",");
Run Code Online (Sandbox Code Playgroud)
执行该函数时,它会引发此异常。
### Error querying database. Cause: java.sql.SQLSyntaxErrorException: ORA-01722: invalid number
### The error may involve com.rs2.automation.soacomparison.dao.differences.DifferencesMapper.getDifferencesByScanIDs-Inline
### The error occurred while setting parameters
### Cause: java.sql.SQLSyntaxErrorException: ORA-01722: invalid number
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。我认为问题在于 mybatis 没有将这些值识别为单独的数字。另一种解决方案是对每个数字执行查询,但我想一次传递所有值。提前致谢。
我在使用Spring Boot + My Batis Spring Boot创建测试时遇到问题我为我的映射器创建了几个U. Test.对于插入,我使用@SelectKey注释来获取序列的下一个值.当Spring回滚时,事务不会回滚序列,并在每个应用程序启动时递增它.
FE.
@RunWith(SpringRunner.class)
@ActiveProfiles(profiles = "local")
@SpringBootTest
@Slf4j
@Transactional
public class MultimediaMapperTest {
@Autowired
private MultimediaMapper multimediaMapper;
@Autowired
private IEmpresasService empresasService;
@Test
public void insertArchivo() {
Multimedia archivo = Multimedia.builder()
.tiposEntidad(TiposEntidad.EMP)
.idEntidad(1)
.awsKey("KEY_AMAZON_WEB_SERVICES")
.nomFichero("fichero.txt")
.mime("application/pdf")
.observaciones("prueba observaciones")
.build();
multimediaMapper.insertArchivos(archivo);
log.debug("Fin de la inserción de {}", archivo);
assertThat(archivo.getIdArchivo(), is(notNullValue()));
}
Run Code Online (Sandbox Code Playgroud)
日志:
首先开始:
[INFO ] 2018-04-23 21:44:16,369 [] o.s.c.s.DefaultLifecycleProcessor - Starting beans in phase 2147483647 [INFO ] 2018-04-23 21:44:16,369 [] s.d.s.w.p.DocumentationPluginsBootstrapper - Context …
我使用 SqlServer 和 MyBatis。
一直在网上寻找几个例子,但似乎没有什么适合我的需要。storage_procedure Im 调用接受 5 个参数并返回 1 个值 - 例如
give_discount(名字、姓氏、性别、出生日期、年龄)
所有这些都是字符串。storage_procedure 然后返回一个 STRING,它应该告诉你你有权享受多少折扣。
这五个属性(FirstName、LastName、DateOfBirth、Age、Gender)存储在名为 Person.java 的 POJO 中
所以假设我创建了一个 Person.java 的实例
Person person1 = new Person();
person1.setFirstName("Joe");
person1.setLastName("Higashi");
person1.setGender("M");
person1.setDateOfBirth("1990-01-01");
person1.setAge("29");
Run Code Online (Sandbox Code Playgroud)
这是我的 mapperXML
<resultMap id = "discountValueParams" type="com.test.Person">
<result property = "FirstName" column = "FirstName"/>
<result property = "LastName" column = "LastName"/>
<result property = "Gender" column = "Gender"/>
<result property = "DateOfBirth" column = "DateOfBirth"/>
<result property = "Age" column = "Age"/>
</resultMap>
Run Code Online (Sandbox Code Playgroud)
所以问题是:
如何将 …
如何在 Java Spring 启动中将 MultipartFile 照片作为 Base64 字符串插入数据库,并将其从数据库显示在主屏幕上。