我正在开发一个基于Spring MVC 3的新Web项目.现在尝试决定是否使用spring form标签.我个人不喜欢使用除HTML和JSP之外的任何标签.学习它们需要时间,很难理解它们是如何呈现的,并且当它们发生时错误消息.那么使用它们有什么突出的优点吗?谢谢!
我的目标是将spring mvc 3配置为不在json响应中返回"null"对象.我问过如何配置spring mvc 3以不在json响应中返回"null"对象?.我得到的建议是配置ObjectMapper,将序列化包含设置为JsonSerialize.Inclusion.NON_NULL.所以基于Spring配置@ResponseBody JSON格式,我在spring配置文件中做了以下更改.但是在应用启动期间我收到错误"拒绝的bean名称'jacksonObjectMapper':没有识别出URL路径org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping:86-AbstractDetectingUrlHandlerMapping.java".
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- Configures the @Controller programming model -->
<mvc:annotation-driven />
<!-- Forwards requests to the "/" resource to the "welcome" view -->
<!--<mvc:view-controller path="/" view-name="welcome"/>-->
<!-- Configures Handler Interceptors -->
<mvc:interceptors>
<!-- Changes the locale when a 'locale' request parameter is sent; e.g. /?locale=de -->
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
</mvc:interceptors>
<!-- Saves a locale change using a cookie -->
<bean …Run Code Online (Sandbox Code Playgroud) 示例代码如下:
$('a').mousedown(function(event)
{
event.ABC = true;
});
$(window).mousedown(function(event)
{
console.log("event.ABC:",event.ABC);
//outputs "undefined "
if( event.ABC)
{
// do sth
}
else
{
//let it go
}
});
Run Code Online (Sandbox Code Playgroud) 在我看来,你需要tomcat或其他一些servlet引擎作为web部分.那么使用hibernate和jms的数据访问部分呢?谢谢.
例如,如果请求成功,我将返回一个View,如果没有,则返回一个指示错误消息的String,并将content-type设置为xml或json.并且JavaScript XHR回调方法将完成重定向到另一个页面(View)或保持在同一页面并显示错误信息的工作.
根据我读到的内容,似乎我应该使用"void"作为处理程序方法的返回类型.检查一下:"如果方法处理响应本身(通过直接写响应内容,为此目的声明类型为ServletResponse/HttpServletResponse的参数)或者假定视图名称应通过RequestToViewNameTranslator隐式确定(无法声明),则为void处理程序方法签名中的响应参数."(Spring Framework参考).
我不明白的是"视图名称应该通过RequestToViewNameTranslator隐式确定(不在处理程序方法签名中声明响应参数)"是什么意思?有人给我举个例子吗?
我有两种方法,一种是应该处理JS发出的登录请求,另一种是处理登录页面.
@RequestMapping(value = "/login", method = {RequestMethod.GET, RequestMethod.HEAD},
headers = "x-requested-with:XMLHttpRequest")
public @ResponseBody String login() {...}
@RequestMapping(value = "/login", method = {RequestMethod.GET, RequestMethod.HEAD})
public String getLoginPage() {......}
Run Code Online (Sandbox Code Playgroud)
但是,所有登录请求似乎都转到getLoginPage方法,无论它是否具有"x-requested-with:XMLHttpRequest"标头.我加倍检查http标头,它包含正确的头.所以看来Spring只是忽略了登录方法.
我一直在努力解决这个问题,任何建议都将不胜感激,谢谢!
非常感谢任何建议.
如果使用MongoRepository,您可以拥有以下代码:
@Repository
public interface UserRepo extends MongoRepository<User, String> {
// additional methods go here
}
Run Code Online (Sandbox Code Playgroud)
然后你做userRepo.save()find()等来做CRUD操作.
或者你只是MongoTemplate并做CRUD操作.
我的问题是哪个更受欢迎?每种方法的优缺点是什么?谢谢!
这是错误日志:
building 'psycopg2._psycopg' extension
creating build/temp.macosx-10.9-intel-2.7
creating build/temp.macosx-10.9-intel-2.7/psycopg
cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.5 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090301 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I. -I/Library/PostgreSQL/9.3/include -I/Library/PostgreSQL/9.3/include/postgresql/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.9-intel-2.7/psycopg/psycopgmodule.o
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in …Run Code Online (Sandbox Code Playgroud) 这 <div id="adiv"></div>将在JSPX中以某种方式被翻译成<div id="adiv" />.我让它工作的方式是在里面添加空注释<div id="adiv"><!-- --></div>.我不明白为什么会这样,有没有更好的解决这个问题?