此调用已弃用:
session.createCriteria(Bus.class).list();
Run Code Online (Sandbox Code Playgroud)
在源文件中,我可以看到:
/** @deprecated */
@Deprecated
Criteria createCriteria(Class var1);
/** @deprecated */
@Deprecated
Criteria createCriteria(Class var1, String var2);
/** @deprecated */
@Deprecated
Criteria createCriteria(String var1);
/** @deprecated */
@Deprecated
Criteria createCriteria(String var1, String var2);
Run Code Online (Sandbox Code Playgroud)
但我无法理解我必须使用哪种方法代替createCriteria.
我有一个小项目,必须回复一些文件.我知道使用nginx将是更好的决定,但文件非常小.
我的计划的一部分:
return send_file(os.path.join(filepath, filename))
Run Code Online (Sandbox Code Playgroud)
该行返回具有文件名的文件,download没有任何格式或类似的东西.已下载的文件名始终相同,不依赖于文件的真实名称.文件的真实名称是table.csv.如何以正确的文件名返回文件?
我上过课了Spring Boot,它完美无缺.但是,如果我想返回一组对象呢?我试着做这个,但它不工作.我该怎么做才能正确?
有一个对象(它的工作原理):
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue = "World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
Run Code Online (Sandbox Code Playgroud)
有很多对象(它不起作用):
@RequestMapping(value = "/greeting", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Greeting> greeting() {
Greeting greeting1 = new Greeting(1, "One");
Greeting greeting2 = new Greeting(2, "Two");
List<Greeting> list = new ArrayList<>();
list.add(greeting1);
list.add(greeting2);
return list;
}
Run Code Online (Sandbox Code Playgroud) 我有 - flask服务.有时我可以json在http标题处获得没有分数的消息.在这种情况下,我正在尝试解析来自的消息request.data.但是字符串来自request.data解析真的很难.这是一个二进制字符串,如下所示:
b'{\n "begindate": "2016-11-22", \n "enddate": "2016-11-22", \n "guids": ["6593062E-9030-B2BC-E63A-25FBB4723ECC", \n "5A9F8478-6673-428A-8E90-3AC4CD764543", \n "D8243BA1-0847-48BE-9619-336CB3B3C70C"]\n}'
Run Code Online (Sandbox Code Playgroud)
当我尝试使用时json.loads(),我收到此错误:
TypeError: the JSON object must be str, not 'bytes'
Run Code Online (Sandbox Code Playgroud)
转换为string(str())的功能也不能很好地工作:
'b\'{\\n "begindate": "2016-11-22", \\n "enddate": "2016-11-22", \\n "guids": ["6593062E-9030-B2BC-E63A-25FBB4723ECC", \\n "5A9F8478-6673-428A-8E90-3AC4CD764543", \\n "D8243BA1-0847-48BE-9619-336CB3B3C70C"]\\n}\''
Run Code Online (Sandbox Code Playgroud)
我用Python 3.我该怎么办才能解析request.data?
我在java上要做的事情:
try(InputStream inputStream = new FileInputStream("/home/user/123.txt")) {
byte[] bytes = new byte[inputStream.available()];
inputStream.read(bytes);
System.out.println(new String(bytes));
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
但kotlin不知道try-with-resources!所以我的代码是
try {
val input = FileInputStream("/home/user/123.txt")
} finally {
// but finally scope doesn't see the scope of try!
}
Run Code Online (Sandbox Code Playgroud)
有没有简单的方法来关闭流?我不会只谈论文件.有没有办法stream轻松关闭?
我正在阅读高级Scala With Cats.我在函子描述(第59页)中坚持这个例子:
object FunctorsDemo extends App {
import cats.instances.function._
import cats.syntax.functor._
val func1 = (x: Int) => x.toDouble
val func2 = (y: Double) => y * 2
val func3 = func1.map(func2) // wrong line for me
}
Run Code Online (Sandbox Code Playgroud)
在书中一切都很好,但我有这个例外:
Error:(10, 21) value map is not a member of Int => Double
val func3 = func1.map(func2)
Run Code Online (Sandbox Code Playgroud)
无法理解我做错了什么.
我写了这个简单的程序:
@app.route('/puttest/', methods=['GET', 'PUT'])
def upload_file():
if request.method == 'PUT':
return 'Hello, {}!'.format(request.form['name'])
else:
return '''
<title>Does it work ?</title>
<h1>PUT test</h1>
<form action=http://localhost:8887/puttest/ method=put>
<input type=text name=name>
<input type=submit value=try>
</form>
'''
if __name__ == '__main__':
app.run('0.0.0.0', 8887)
Run Code Online (Sandbox Code Playgroud)
它适用于GET方法,但它无法使用PUT.尝试发送put消息,我可以在浏览器中看到此错误:
Method Not Allowed
The method is not allowed for the requested URL.
Run Code Online (Sandbox Code Playgroud)
put方法发生了什么?
如果我在程序中的任何地方改变put方法,它将工作正常post.
我读过有关无标签决赛的内容,我认为这很棒。我想建立自己的这种模式的小例子,并解决了问题。
这是我的代码:
trait Calculator[F[_]] {
def sum(a: Int, b: Int): F[Either[Throwable, Int]]
def minus(a: Int, b: Int): F[Either[Throwable, Int]]
}
object calculatorInstances {
implicit val futureCalculator: Calculator[Future] = new Calculator[Future] {
override def sum(a: Int, b: Int) =
Future {
Try(a + b).toEither
}
override def minus(a: Int, b: Int) =
Future {
Try(a - b).toEither
}
}
}
import calculatorInstances.futureCalculator
def getPlusAndMinus[F[_]: Monad: Calculator](a: Int, b: Int): F[Either[String, Int]] = {
for {
sum <- Calculator[F].sum(a, b)
res <- …Run Code Online (Sandbox Code Playgroud) java ×3
python ×3
flask ×2
scala ×2
scala-cats ×2
hibernate ×1
json ×1
kotlin ×1
put ×1
python-3.x ×1
spring ×1
spring-boot ×1