我有以下用于JodaTime处理的Serializer:
public class JodaDateTimeJsonSerializer extends JsonSerializer<DateTime> {
private static final String dateFormat = ("MM/dd/yyyy");
@Override
public void serialize(DateTime date, JsonGenerator gen, SerializerProvider provider)
throws IOException, JsonProcessingException {
String formattedDate = DateTimeFormat.forPattern(dateFormat).print(date);
gen.writeString(formattedDate);
}
}
Run Code Online (Sandbox Code Playgroud)
然后,在每个模型对象上,我这样做:
@JsonSerialize(using=JodaDateTimeJsonSerializer.class )
public DateTime getEffectiveDate() {
return effectiveDate;
}
Run Code Online (Sandbox Code Playgroud)
通过以上设置,@ResponseBodyJackson Mapper确实有效.但是,我不喜欢我一直在写的想法@JsonSerialize.我需要的是没有@JsonSerializeon模型对象的解决方案.是否可以将此配置在spring xml中的某个位置编写为一个配置?
感谢您的帮助.
编辑:我的Spring框架版本3.0.5
这是一个小问题,当我点击语言转换器链接时,语言没有改变.
语言文件(messages_xx.properties)位于类路径i18n目录中.文件是:
i18n/messages_en.properties
i18n/messages_ar.properties
Run Code Online (Sandbox Code Playgroud)
弹簧配置
<!-- Component scanner. This is used to automatically find Spring annotations like @Service and @Repository -->
<context:component-scan base-package="com.keype" />
<!-- Annotation driven programming model -->
<mvc:annotation-driven />
<context:annotation-config />
<mvc:resources mapping="/static/**" location="/static/" />
<!-- Session Object Configuration -->
<bean id="session" class="com.keype.system.Session" scope="session">
<aop:scoped-proxy />
</bean>
<!-- The View Resolver -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp"
/>
<!-- i18n Configuration. Default language is english. Change language using ?language=en -->
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" …Run Code Online (Sandbox Code Playgroud) My Domain对象有几个Joda-Time DateTime字段.当我使用SimpleJdbcTemplate读取数据库值时:
患者患者= jdbc.queryForObject(sql,new BeanPropertyRowMapper(Patient.class),patientId);
它只是失败,令人惊讶的是,没有记录任何错误.我想这是因为timestamp解析DateTime不适用于Jdbc.
如果可以继承和覆盖BeanPropertyRowMapper并指示转换all java.sql.Timestamp和java.sql.Dateto DateTime,那就太棒了,可以节省很多额外的代码.
有什么建议?
伙计们,我做了足够多的研究,但我找不到解决方法.
简而言之,我只是将url编码的表单数据传递给Controller方法,并尝试将其转换为具有Date和整数的域对象.
@RequestMapping(value = "/savePassport", method = RequestMethod.POST)
public @ResponseBody
AjaxResponse savePassport(@RequestBody StaffPassport passport, HttpServletResponse response) {
// Some operations.
Run Code Online (Sandbox Code Playgroud)
}
员工护照看起来像这样:
import java.sql.Date;
public class StaffPassport {
private int staffId;
private String passportNumber;
private String placeOfIssue;
private Date issueDate;
private Date expiryDate;
private String spouseName;
private String oldPassportRef;
private String visaInfo;
private String description;
//gets/sets
}
Run Code Online (Sandbox Code Playgroud)
当我调用/ savePassport时,我得到不支持的媒体异常.我猜这与铸造有关.
我不能正常工作.当然我可以使用@RequestParam捕获单独的表单数据并手动进行转换,但这不是框架的重点不是吗?
我哪里错了?而你是对的.我是春天的初学者,但我喜欢它.
我正在尝试使用Spring MVC和Apache Shiro建立一个环境.我正在关注shiro.apache.org中提到的文章.
我在web.xml中使用Spring的DelegatingFilterProxy作为Shiro Filter.
使用以下命令完成当前过滤:
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<property name="loginUrl" value="/login"/>
<property name="successUrl" value="/dashboard"/>
<property name="unauthorizedUrl" value="/unauthorized"/>
<property name="filterChainDefinitions">
<value>
/** = authc, user, admin
/admin/** = authc, admin
/login = anon
</value>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
问题是,如何使用定义安全设置的shiro.ini文件?
平台:Shiro 1.1.0,Spring 3.0.5
我正在尝试使用Shiro注释来保护MVC Controller方法.但是注释有问题.普通电话正常工作.Shiro调试中也没有具体的内容.
我的shiro配置:
<!-- Security Manager -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="sessionMode" value="native" />
<property name="realm" ref="jdbcRealm" />
<property name="cacheManager" ref="cacheManager"/>
</bean>
<!-- Caching -->
<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<property name="cacheManager" ref="ehCacheManager" />
</bean>
<bean id="ehCacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />
<bean id="sessionDAO"
class="org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO" />
<bean id="sessionManager"
class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
<property name="sessionDAO" ref="sessionDAO" />
</bean>
<!-- JDBC Realm Settings -->
<bean id="jdbcRealm" class="org.apache.shiro.realm.jdbc.JdbcRealm">
<property name="name" value="jdbcRealm" />
<property name="dataSource" ref="dataSource" />
<property name="authenticationQuery"
value="SELECT password FROM system_user_accounts WHERE username=? and status=1" />
<property …Run Code Online (Sandbox Code Playgroud) 情况是这样的:
PostgreSQL数据库表中有一个字段dateAdded是timestamp
Pojo模型对象将此字段映射为
class MyModel{
org.joda.time.DateTime dateAdded;
}
Run Code Online (Sandbox Code Playgroud)
我的Dao实现是在Spring JDBC Template中,它如下:
SqlParameterSource parameters = new BeanPropertySqlParameterSource(patient);
jdbcInsert.execute(parameters);
Run Code Online (Sandbox Code Playgroud)
我从客户端读取模型并使用构建对象@Model.到目前为止一切都很好.当我执行此操作时,数据库抛出一个异常说:
[编辑Erwin]:结果异常不是来自数据库.
org.postgresql.util.PSQLException: Bad value for type timestamp : 2011-10-10T21:55:19.790+03:00
Run Code Online (Sandbox Code Playgroud)
我不想通过实现完整的INSERT语句手动进行格式化,因为涉及许多字段.
这里最好的解决方案是什么?有没有配置方式toString()的DateTime所有呼叫.我还想过从DateTime创建一个继承的类但是... mmhh ..这是一个决赛.
-
Per Erwin,我通过插入虚拟表来测试DateTime值'2011-10-10T21:55:19.790 + 03:00'并且它正在工作.但无法使用JDBC.与JDBC驱动程序有关的东西?
Java 1.7/Spring 3.1
看看下面的代码。
BigDecimal value = queryAsObject (BigDecimal.class,
"select balance from financial.accounts where account_id = ?", accountId);
Run Code Online (Sandbox Code Playgroud)
其中 queryAsObject 来自一个抽象父类,它基本上执行 CRUD 操作。
public <T> T queryAsObject(Class<T> modelClass, String sql, Object... args) {
return jdbcTemplate.queryForObject(sql, new HawkBeanPropertyRowMapper<T>(modelClass), args);
}
Run Code Online (Sandbox Code Playgroud)
非常简单的 Spring jdbc 调用。但是它会导致以下异常:
org.springframework.web.util.NestedServletException: Request processing failed;
nested exception in org.springframework.beans.BeanInstantiationException:
Could not instantiate bean class [java.math.BigDecimal]:
Is it an abstract class?; nested exception is
java.lang.InstantiationException: java.math.BigDecimal
Run Code Online (Sandbox Code Playgroud)
根本原因:
org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.math.BigDecimal]: Is it an abstract class?; …Run Code Online (Sandbox Code Playgroud) 我正在使用一个Web应用程序,其中多个应用程序通过CAS SSO服务器进行身份验证。但是,每个应用程序应保持各自的角色,并且这些角色存储在特定于该应用程序的数据库中。因此,我需要有2个领域,一个领域用于CAS(用于authc),另一个领域用于DB(用于authz)。
这是我当前的Shiro配置。我正在重定向到CAS,但工作正常,但是登录的用户(Subject)似乎没有加载角色/权限(例如,SecurityUtil.isPermitted()不能按预期工作)
<bean id="jdbcRealm" class="org.apache.shiro.realm.jdbc.JdbcRealm">
<property name="name" value="jdbcRealm" />
<property name="dataSource" ref="dataSource" />
<property name="authenticationQuery"
value="SELECT password FROM system_user_accounts WHERE username=? and status=10" />
<property name="userRolesQuery"
value="SELECT role_code FROM system_roles r, system_user_accounts u, system_user_roles ur WHERE u.user_id=ur.user_id AND r.role_id=ur.role_id AND u.username=?" />
<property name="permissionsQuery"
value="SELECT code FROM system_roles r, system_permissions p, system_role_permission rp WHERE r.role_id=rp.role_id AND p.permission_id=rp.permission_id AND r.role_code=?" />
<property name="permissionsLookupEnabled" value="true"></property>
<property name="cachingEnabled" value="true" />
<property name="credentialsMatcher" ref="passwordMatcher" />
</bean>
<!-- For CAS -->
<bean id="casRealm" class="org.apache.shiro.cas.CasRealm"> …Run Code Online (Sandbox Code Playgroud) 此轮播中共有2个项目/图像.加载第二个图像后,Carousel尝试移动到第三个项目(没有),旋转木马就消失了.在中间层之后,旋转木马返回第一张图像.
旋转木马滑动像..
Item 1 > Item 2 > Disappear > Item 1 > ...
Run Code Online (Sandbox Code Playgroud)
该版本是Bootstrap 2.1和jQuery 1.8.1.下面是代码.
<script type="text/javascript" src="media/jui/js/jquery.min.js"></script>
<script type="text/javascript" src="media/jui/js/bootstrap.min.js"></script>
<div id="homeCarousel" class="carousel">
<div class="carousel-inner">
<div class="item active">
<img src="images/hawk2.jpg" alt="" >
</div>
<div class="item">
<img src="images/hawk5.jpg" alt="" >
</div>
<div class="carousel-caption">
<ul class="nav nav-tabs">
<li class="active"><a href="#home" data-toggle="tab">
<h1>**</h1>
<h4>Business Applications</h4>
</a></li>
<li><a href="#profile" data-toggle="tab"><h1>**</h1>
<h4>IT Infrastructure</h4></a></li>
<li><a href="#messages" data-toggle="tab"><h1>**</h1>
<h4>Web & Content</h4></a></li>
</ul>
</div>
<a class="carousel-control right" href="#homeCarousel" data-slide="next">›</a>
<a class="carousel-control left" href="#homeCarousel" data-slide="prev">‹</a>
</div> …Run Code Online (Sandbox Code Playgroud)