我想在我的控制器中使用带注释的原型bean.但是春天正在创造一个单身豆.这是代码:
@Component
@Scope("prototype")
public class LoginAction {
private int counter;
public LoginAction(){
System.out.println(" counter is:" + counter);
}
public String getStr() {
return " counter is:"+(++counter);
}
}
Run Code Online (Sandbox Code Playgroud)
控制器代码:
@Controller
public class HomeController {
@Autowired
private LoginAction loginAction;
@RequestMapping(value="/view", method=RequestMethod.GET)
public ModelAndView display(HttpServletRequest req){
ModelAndView mav = new ModelAndView("home");
mav.addObject("loginAction", loginAction);
return mav;
}
public void setLoginAction(LoginAction loginAction) {
this.loginAction = loginAction;
}
public LoginAction getLoginAction() {
return loginAction;
}
}
Run Code Online (Sandbox Code Playgroud)
速度模板:
LoginAction counter: ${loginAction.str}
Run Code Online (Sandbox Code Playgroud)
Spring config.xml启用了组件扫描:
<context:annotation-config /> …Run Code Online (Sandbox Code Playgroud) 我试图了解fold和foldLeft以及各自的reduce和reduceLeft是如何工作的.我用fold和foldLeft作为例子
scala> val r = List((ArrayBuffer(1, 2, 3, 4),10))
scala> r.foldLeft(ArrayBuffer(1,2,4,5))((x,y) => x -- y._1)
scala> res28: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(5)
scala> r.fold(ArrayBuffer(1,2,4,5))((x,y) => x -- y._1)
<console>:11: error: value _1 is not a member of Serializable with Equals
r.fold(ArrayBuffer(1,2,4,5))((x,y) => x -- y._1)
Run Code Online (Sandbox Code Playgroud)
为什么fold不工作foldLeft?什么是Serializable with Equals?我理解fold和foldLeft在参数泛型类型方面有轻微不同的API签名.请指教.谢谢.
如何配置build.sbt以排除src/main/java目录?我想把我的Java源代码放在那里,但我不想编译它们.此外,我可以排除使用RE指定的文件或文件组.这些可以在build.sbt中轻松配置吗?
这个问题的产生是因为我想捕捉LostFocusEvent的Dialog.不幸的是,非Component派生组件不会触发此事件.我想问的是,Dialog不是从Component派生的目标是什么,而是RichWindow与Swing库相比?
我试图将此Scala函数转换为返回惰性流,而不是急切地检索所有结果,并在所有结果都存在时将它们从Seq转换为Stream.我感觉问题在于(for(i < - 1到9; z < - solve(xs.updated(pos,i),pos))yield z)toStream.
任何建议表示赞赏.我正在寻找的另一个解决方案是在找到结果时返回结果.使用此解决方案,我可能只返回了1个结果.谢谢
isConflictAt(xs.updated(pos, 0), pos, xs(pos) 是约束检查功能.
def solve(xs : List[Int], pos: Int): Stream[List[Int]] = {
if (!isConflictAt(xs.updated(pos, 0), pos, xs(pos))) {
val pos = xs.indexOf(0)
if (pos < 0) {println(xs); Stream(xs) } else (for (i <- 1 to 9; z <- solve(xs.updated(pos, i), pos)) yield z) toStream
} else Stream.empty
}
Run Code Online (Sandbox Code Playgroud) I was reading this article, , about subclassing a builder class. I understood the article but there was one small bit that bothered me. There was this method,
public static Builder<?> builder() {
return new Builder2();
}
Run Code Online (Sandbox Code Playgroud)
When I changed Builder<?> to Builder, a raw type, the compiler would not compile the code. The error was,
Rectangle.java:33: error: cannot find symbol
System.out.println(Rectangle.builder().opacity(0.5).height(250);
Run Code Online (Sandbox Code Playgroud)
What was the additional information passed to the compiler using the additional <?>? I suspected it …
使用Scalaz,函数可以映射到另一个函数.什么时候我会想使用map过andThen?使用有明显的优势map吗?谢谢
例如,
val f: Int => Int = (a) => a + 10
val g: Int => Int = (a) => a * 100
(f map g map {_*3})(10) == (f andThen g andThen {_*3})(10) // true
Run Code Online (Sandbox Code Playgroud) 我是Scala的新手,并按照其中一个例子让Swing在Scala工作,我有一个问题.基于,
listenTo(celsius, fahrenheit)
reactions += {
case EditDone(`fahrenheit`) =>
val f = Integer.parseInt(fahrenheit.text)
celsius.text = ((f - 32) * 5 / 9).toString
case EditDone(`celsius`) =>
val c = Integer.parseInt(celsius.text)
fahrenheit.text = ((c * 9) / 5 + 32).toString
}
Run Code Online (Sandbox Code Playgroud)
为什么我必须在EditDone(`fahrenheit`)和EditDone(`celsius`)中使用反引号(`)来识别我的文本域组件,例如fahrenheit和celsius?为什么我不能用EditDone(fahrenheit)呢?
谢谢
我正在追随Clojure的喜悦,我对这两个陈述感到困惑
(def very-lazy (-> (iterate #(do (print \.) (inc %)) 1) rest rest rest))
(def less-lazy (-> (iterate #(do (print \.) (inc %)) 1) next next next))
Run Code Online (Sandbox Code Playgroud)
因此,产量是
(println (first very-lazy)) ; .4
(println (first less-lazy)) ; 4
Run Code Online (Sandbox Code Playgroud)
这本书继续解释这一点
抓住使用rest构建的lazy seq中的第一个元素会导致实现预期.但是对于使用next构建的seq也不会发生这种情况,因为它之前已经实现过.使用next会导致lazy seq成为一个不太懒的元素,如果实现成本很高,则可能不需要.
我的问题是为什么"非常懒"会有一个额外的点?我的想法是"打印"将打印其参数时,如果不考虑调用next或rest.
谢谢
我有一个带模块的现有SBT项目.我想将Play 2.2添加到我的项目中作为子模块.这个新的Play模块将取决于其他模块.
到目前为止我发现的主要是关于Play是支持模块的主要项目.如果Play确实支持此设置,请指出我正确的方向如何做到这一点.谢谢.
我想要的设置(简化):
my_project
\--- desktop_ui
\--- src/main
\--- src/test
\--- common
\--- src/main
\--- src/test
\--- web_ui (Play framework)
\--- app/controllers
\--- app/views
\--- app/models
\--- conf
Run Code Online (Sandbox Code Playgroud)