是否可以在Jira评论中添加突出显示的代码?我想写这样的东西:
评论文本和JSON文档:
{
"key": 100
}
Run Code Online (Sandbox Code Playgroud)
我发现只有一个例子:
{code:javascript}
{
"key": 100
}
{code}
Run Code Online (Sandbox Code Playgroud)
但它并没有真正突出我的代码.我只看到灰色块.
我试图将JSON文件用作小型数据库.在DataFrame上创建模板表后,我用SQL查询它并获得异常.这是我的代码:
val df = sqlCtx.read.json("/path/to/user.json")
df.registerTempTable("user_tt")
val info = sqlCtx.sql("SELECT name FROM user_tt")
info.show()
Run Code Online (Sandbox Code Playgroud)
df.printSchema() 结果:
root
|-- _corrupt_record: string (nullable = true)
Run Code Online (Sandbox Code Playgroud)
我的JSON文件:
{
"id": 1,
"name": "Morty",
"age": 21
}
Run Code Online (Sandbox Code Playgroud)
Exeption:
Exception in thread "main" org.apache.spark.sql.AnalysisException: cannot resolve 'name' given input columns: [_corrupt_record];
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
UPD
_corrupt_record 是
+--------------------+
| _corrupt_record|
+--------------------+
| {|
| "id": 1,|
| "name": "Morty",|
| "age": 21|
| }|
+--------------------+
Run Code Online (Sandbox Code Playgroud)
UPD2
这很奇怪,但是当我重写我的JSON以使其成为oneliner时,一切正常.
{"id": 1, "name": "Morty", "age": 21}
Run Code Online (Sandbox Code Playgroud)
所以问题在于newline.
UPD3
我在文档中找到了下一句话: …
我想知道如何Tomcat在Spring MVC上引导我的应用程序?
我有一个初始化器:
public class AppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) {
AnnotationConfigWebApplicationContext rootCtx = new AnnotationConfigWebApplicationContext();
rootCtx.register(AppConfig.class);
container.addListener(new ContextLoaderListener(rootCtx));
AnnotationConfigWebApplicationContext dispatcherCtx = new AnnotationConfigWebApplicationContext();
dispatcherCtx.register(FreeMarkerWebConfig.class);
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherCtx));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
Run Code Online (Sandbox Code Playgroud)
我知道为什么我们需要web.xml以及如何Tomcat使用它来引导应用程序.但我不明白Tomcat如果没有xml文件,它是如何知道应该使用哪个servlet来引导应用程序,但只是AppAppInitializer?
依赖
<!-- spring mvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<!-- servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
...
Run Code Online (Sandbox Code Playgroud)
我在Spring核心中找到了这个类SpringServletContainerInitializer.Tomcat …
我有多个复选框
<div class="data">
<span>
<input name="employee" type="checkbox" value="Alex"/>
<label for="employee">Alex</label>
</span>
<span>
<input name="employee" type="checkbox" value="Frank"/>
<label for="employee">Frank</label>
</span>
<span>
<input name="employee" type="checkbox" value="Mark"/>
<label for="employee">Mark</label>
</span>
</div>
Run Code Online (Sandbox Code Playgroud)
如何找到所有选中的复选框并创建带有检查结果的json或数组?
为什么可以从子实例访问我的超类的静态方法?
public class Test {
public static void main(String[] args) {
new UtilImpl().fun();
new AbstractUtil() {}.fun();
}
static abstract class AbstractUtil {
public static void fun() {
System.out.println("Fun!");
}
}
static class UtilImpl extends AbstractUtil {
}
}
Run Code Online (Sandbox Code Playgroud)
我同意从父类的实例访问父类的静态方法。但是如果我实例化一个子类,访问父类的静态上下文就很奇怪了。
聚苯乙烯
在实例上调用静态方法有什么好处?
我import在一些发现了以下内容scala:
import Predef.{println => _, _}
Run Code Online (Sandbox Code Playgroud)
怎么=>办?
我正在玩ScalikeJdbc图书馆.我想从PostgreSQL数据库中检索数据.我得到的错误对我来说很奇怪.即使我手动配置CP:
val poolSettings = new ConnectionPoolSettings(initialSize = 100, maxSize = 100)
ConnectionPool.singleton("jdbc:postgresql://localhost:5432/test", "user", "pass", poolSettings)
Run Code Online (Sandbox Code Playgroud)
我仍然看到错误.这是我的DAO:
class CustomerDAO {
case class Customer(id: Long, firstname: String, lastname: String)
object Customer extends SQLSyntaxSupport[Customer]
val c = Customer.syntax("c")
def findById(id: Long)(implicit session: DBSession = Customer.autoSession) =
withSQL {
select.from(Customer as c)
}.map(
rs => Customer(
rs.int("id"),
rs.string("firstname"),
rs.string("lastname")
)
).single.apply()
}
Run Code Online (Sandbox Code Playgroud)
该应用程序:
object JdbcTest extends App {
val dao = new CustomerDAO
val res: Option[dao.Customer] = dao.findById(2)
}
Run Code Online (Sandbox Code Playgroud)
我的application.conf档案 …
我有一个代码,我需要设置三个表.为此,我需要jdbc为每个表调用三次函数.见下面的代码
val props = new Properties
props.setProperty("user", "root")
props.setProperty("password", "pass")
val df0 = sqlContext.read.jdbc(
"jdbc:mysql://127.0.0.1:3306/Firm42", "company", props)
val df1 = sqlContext.read.jdbc(
"jdbc:mysql://127.0.0.1:3306/Firm42", "employee", props)
val df2 = sqlContext.read.jdbc(
"jdbc:mysql://127.0.0.1:3306/Firm42", "company_employee", props)
df0.registerTempTable("company")
df1.registerTempTable("employee")
df2.registerTempTable("company_employee")
val rdf = sqlContext.sql(
"""some_sql_query_with_joins_of_various_tables""".stripMargin)
rdf.show
Run Code Online (Sandbox Code Playgroud)
是否可以简化我的代码?或者也许有一些方法可以在SQL配置中的某处指定多个表.
我找到了一个Scala代码片段,它声明了一个方法<init>并放在()调用之下.
我对第5行有疑问.()这里的意思是什么?
(() => {
final class $anon extends MutableProjection {
def <init>() = {
super.<init>();
()
};
...
};
new $anon()
})
Run Code Online (Sandbox Code Playgroud)
这是一个完整示例的代码.
这是我的代码片段:
implicit def trick(s: String): String = s.toUpperCase
def fun(s: String)(implicit f: String => String): String = f(s)
println(s"String is ${fun("abc")}")
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它打印"abc"而不是"ABC".我在这做错了什么?
PS
但是,如果我运行下一个代码
implicit val n: Int = 100
def add(n1: Int)(implicit n2: Int) = n1 + n2
add(7)
Run Code Online (Sandbox Code Playgroud)
所有隐含的魔法都很好.
scala ×5
apache-spark ×2
java ×2
arrays ×1
checkbox ×1
javascript ×1
jira ×1
json ×1
postgresql ×1
scalikejdbc ×1
spring ×1
sql ×1