也许是个愚蠢的问题.但到目前为止我还没有找到答案.那么如何在SLICK中表示SQL的"LIKE"运算符?
我正在尝试使用SLICK 1.0.0生成此SQL:
select
cat.categoryId,
cat.title,
(
select
count(product.productId)
from
products product
right join products_categories productCategory on productCategory.productId = product.productId
right join categories c on c.categoryId = productCategory.categoryId
where
c.leftValue >= cat.leftValue and
c.rightValue <= cat.rightValue
) as productCount
from
categories cat
where
cat.parentCategoryId = 2;
Run Code Online (Sandbox Code Playgroud)
我最成功的尝试是(我删除了"连接"部分,因此它更具可读性):
def subQuery(c: CategoriesTable.type) = (for {
p <- ProductsTable
} yield(p.id.count))
for {
c <- CategoriesTable
if (c.parentId === 2)
} yield(c.id, c.title, (subQuery(c).asColumn))
Run Code Online (Sandbox Code Playgroud)
这会在子查询中产生缺少括号的SQL:
select
x2.categoryId,
x2.title,
select count(x3.productId) from products x3
from …Run Code Online (Sandbox Code Playgroud) 我使用Slick 1.0.0-RC1.我有这个表对象的定义:
object ProductTable extends Table[(Int, String, String, String, Double, java.sql.Date, Int, Option[Int], Int, Boolean)]("products") {
def id = column[Int]("productId", O.PrimaryKey, O.AutoInc)
def title = column[String]("title")
def description = column[String]("description")
def shortDescription = column[String]("shortDescription")
def price = column[Double]("price")
def addedDate = column[java.sql.Date]("addedDate")
def brandId = column[Int]("brandId")
def defaultImageId = column[Option[Int]]("defaultImageId")
def visitCounter = column[Int]("visitCounter")
def archived = column[Boolean]("archived")
def * = id ~ title ~ description ~ shortDescription ~ price ~ addedDate ~ brandId ~ defaultImageId ~ visitCounter ~ …Run Code Online (Sandbox Code Playgroud) 我需要使用如下方法:
DoSomething<(T)>();
Run Code Online (Sandbox Code Playgroud)
但我不知道我有哪种类型,只有类型的对象.如果我只有以下情况,我该如何调用此方法:
Type typeOfGeneric;
Run Code Online (Sandbox Code Playgroud) 请帮助我找出如何允许mysql连接器j定义用户变量并使此代码有效:
Statement s = conn.createStatement();
s.executeQuery ("set @categoryId := (Select CategoryId from categories order by CategoryId desc LIMIT 1);\n" +
"set @categoryId := IF(@categoryId is Null, 1, @categoryId);");
Run Code Online (Sandbox Code Playgroud)
现在它引发了一个异常:
MySQLSyntaxErrorException occured : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set @categoryId := IF(@categoryId is Null, 1, @categoryId)' at line 2
Run Code Online (Sandbox Code Playgroud)
我知道在.net中你可以在连接字符串中定义"允许用户变量=真"选项.如何在java中做到这一点?
我是Java世界的新手。我有一个简单的查询问题:
<insert id="create" parameterType="models.entities.CategoryEntity">
set @catId := (select categoryId from Categories limit 1);
insert into Categories(CategoryId, Title, LeftValue, RightValue)
values(@catId, 'Test in', 1,2);
....
</insert>
Run Code Online (Sandbox Code Playgroud)
当我尝试使用mybatis运行它时,它只是失败了:
PersistenceException occured : ### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insert into Categories(CategoryId, Title, LeftValue, RightValue) values(' at line 2 ### The error may involve Category.create-Inline ### The error occurred …Run Code Online (Sandbox Code Playgroud) 我一直在实现具有以下操作的RESTful Web服务:
列出文章:
GET /articles
Run Code Online (Sandbox Code Playgroud)
删除文章(只能将选定的文章删除到垃圾箱中):
DELETE /articles
Run Code Online (Sandbox Code Playgroud)
列出垃圾箱中的文章:
GET /trash/articles
Run Code Online (Sandbox Code Playgroud)
我必须执行一项操作,以将“文章”从“ /垃圾箱/文章”还原回“ /文章”。
这是问题。你平时怎么做?我必须使用什么网址?
我想出了两种方法。第一个是:
DELETE /trash/articles
Run Code Online (Sandbox Code Playgroud)
但是感觉很奇怪,用户可以像“永久删除它,不要还原”那样阅读它。
第二种方法是
PUT /trash/articles
Run Code Online (Sandbox Code Playgroud)
这更奇怪,并且用户将对该操作的执行感到困惑。
我是REST的新手,所以请建议您通常如何做。我尝试在Google中搜索,但不知道如何正确查询,因此没有得到任何有用的信息。