我有以下课程:
public class Container {
private String name;
private Data data;
}
public class Data {
private Long id;
}
Run Code Online (Sandbox Code Playgroud)
当我Container使用Jackson 序列化课程时,我得到了
{"name":"Some name","data":{"id":1}}
Run Code Online (Sandbox Code Playgroud)
但我需要的结果是:
{"name":"Some name","id":1}
Run Code Online (Sandbox Code Playgroud)
是否有可能(没有添加Container.getDataId()方法)?如果是这样,怎么办?
更新
我试图创建自定义,JsonSerializer<Data>但结果与以前一样
public class JsonDataSerializer extends JsonSerializer<Data> {
private static Logger logger = Logger.getLogger(JsonDataSerializer.class);
@Override
public void serialize(Data value, JsonGenerator jgen,
SerializerProvider provider)
throws IOException,JsonProcessingException {
Long id = (value.getId() == null) ? 0l : value.getId();
jgen.writeStartObject();
jgen.writeNumberField("id", id);
jgen.writeEndObject();
logger.debug("Data id " + id + …Run Code Online (Sandbox Code Playgroud) 我想完全国际化我的网页,并将网址翻译成不同的语言.例如
所有上述页面应该由同一个控制器处理并显示相同的内容(当然,翻译成所需的语言,我知道该怎么做 - 使用消息属性).
所以我的问题是:
@RequestMapping注释实现此功能?属性文件:
alias.page=page:pagina
Run Code Online (Sandbox Code Playgroud)
调节器
@RequestMapping("${alias.page}")
...
Run Code Online (Sandbox Code Playgroud)
或类似的东西.
谢谢你的回答.
我想使用ExtJS4创建TreePanel.所以我将JSON发送到具有以下格式的代理阅读器
{
"text": "en",
"children": {
"text": "/",
"children": [{
"text": "/page",
"children": [{
"text": "/page/new",
"children": [],
"leaf": true,
"expanded": false
},
{
"text": "/page/remove",
"children": [],
"leaf": true,
"expanded": false
}
],
"leaf": false,
"expanded": false
},
{
"text": "/home",
"children": [],
"leaf": true,
"expanded": false
}
],
"leaf": false,
"expanded": true
}
}
Run Code Online (Sandbox Code Playgroud)
如果我希望en节点作为我的根节点,如何配置我的商店.
Ext.define('Example.store.WebItems', {
extend: 'Ext.data.TreeStore',
model: 'Example.model.Item',
proxy: {
type: 'ajax',
api: {
read: 'some/url',
},
reader: {
type: 'json',
root: 'children' …Run Code Online (Sandbox Code Playgroud) 枚举有利于创建单身人士.我知道枚举方法不是线程安全的,所以我试着让它成为线程安全的.任何人都可以确认这种实施是否正确.是否可以使用静态和易失性这么多地方并且可以进行优化?由于内部类是私有的,因此我必须在枚举中创建函数以访问内部类功能.可以优化吗?
import java.util.Date;
public enum SingletonWithEnum {
INSTANCE;
private static class Singleton{
private static volatile int count;
private static volatile Date date;
public static int getCount() { return count;}
public static void setCount(int countParam) { synchronized(Singleton.class){ count = countParam; }}
public static Date getDate() { return date;}
public static void setDate(Date dateParam) { synchronized(Singleton.class){ date = dateParam;}}
public static String printObject() {
return "Singleton [count=" + getCount() + ", date=" + getDate() + "]";
}
}
public int getCount() { …Run Code Online (Sandbox Code Playgroud) 我正在编写自定义处理程序拦截器以获得多语言URL地址.例如,当用户访问uri时/de/auto,将出现deutsch内容,当用户访问时,/en/car将出现英语内容.我希望两个请求都重定向到同一个控制器和相同的方法:
@Controller
public class MultiLangController {
@RequestMapping(value="/en/car", method = RequestMethod.GET)
public @ResponseBody String writePage() {
return "some content";
}
Run Code Online (Sandbox Code Playgroud)
我的拦截器是这样实现的(简化版):
public class MultiLangInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
String requestUrl = request.getRequestURI().substring(request.getContextPath().length());
if ("/de/auto".equals(requestUrl)) {
String redirect = request.getContextPath() + "/en/car";
response.sendRedirect(redirect);
return false;
}
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我/en/car在浏览器中访问url时,返回正确的页面(带有"some content"消息),日志显示请求通过我的拦截器传递.当我访问时/de/auto,返回404错误并根据日志请求没有进入我的拦截器.但为什么?不应该请求通过所有拦截器,直到其中一个拦截器通过返回false来阻止它?
为清楚起见,我没有使用,mvc:annotation-driven因为它隐藏了我的自定义拦截器.我已经定义了所有的手段
<bean id="handlerMapping"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors"> …Run Code Online (Sandbox Code Playgroud) 嗨,我试图从Map中删除对象,我正在使用assert测试此操作
// definition of map
private Map<String, Map<Long, Object>> groups = new HashMap<String, Map<Long, Object>>();
// this does not remove item from map
assert groups.get("key").remove(id) != null;
// this removes item from map
groups.get("key").remove(id);
Run Code Online (Sandbox Code Playgroud)
上述方法在相同数据上进行了测试.为什么Map.remove()不能与assert一起使用?
我正在使用EJB 3.1开发java企业Web应用程序,我想知道在哪个MVC层上使用哪种技术.我有耳,ejb(jar)和战争项目.
是否有可能使用其他东西作为持久层然后JPA实现(例如myBatis)以及如何?我想自己管理一些更难的查询.
除了JSF或普通servlet之外,在web项目(war)中使用什么框架?
我熟悉Spring,是否有可能在Web(战争)项目中使用Spring并从其控制器中获益?
您能解释一下哪些技术用于开发企业Web应用程序?
谢谢.
我正在尝试创建简单的 Apache Spark 应用程序,该应用程序将使用 Datastax Cassandra 连接器连接到 Cassandra 并执行一些操作,但出现错误
Symbol 'type <none>.package.DataFrame' is missing from the classpath.
我的build.sbt:
name := "spark-app"
version := "1.0"
scalaVersion := "2.11.11"
libraryDependencies ++= Seq(
"com.datastax.spark" %% "spark-cassandra-connector" % "2.0.0",
"org.apache.spark" %% "spark-core" % "2.1.1" % "provided"
)
resolvers += "Spark Packages Repo" at "https://dl.bintray.com/spark-packages/maven"
Run Code Online (Sandbox Code Playgroud)
我的简单应用:
package com.budgetbakers.be.dwh.spark
import com.datastax.spark.connector._
import org.apache.spark.{SparkConf, SparkContext}
object Distinct {
def main(args: Array[String]): Unit = {
val conf = new SparkConf(true)
.set("spark.cassandra.connection.host", "127.0.0.1")
val sc = new …Run Code Online (Sandbox Code Playgroud) java ×6
spring ×3
json ×2
url ×2
apache-spark ×1
assert ×1
cassandra ×1
datastax ×1
ejb ×1
enums ×1
extjs4 ×1
interceptor ×1
jackson ×1
map ×1
multilingual ×1
persistence ×1
root ×1
sbt ×1
scala ×1
singleton ×1
translation ×1
tree ×1
view ×1