ITeye博客

spring

共 7 篇文章

spring 配置 读取 properties文件 改为 读取数据库

一. 问题 spring 配置通常读取 .properties 文件;小项目 配置少;分布式项目 配置文件比较多;不容易运维维护;可以改为读取数据库,在数据库维护; 二. Spring 的已有解决方案 参考:https://www.codeproject.com/articles/28893/loading-application-properties-from-a-database 必须的jar包 spring.jar (Spring Core) [PropertiesPlaceholderConfigurer] spring-modules.jar (Spring Modules) [C…

2016-12-02 14:11 · spring

spring mvc 参数传递 400 415、list传参

1.默认的 spring mvc 不支持 参数 直接 接收 list ,需要 把list封装 在javabean中 2.@RequestBody注解 把json字符串 映射到 java 实体上 ,注意:ajax传 josn时 需要传 json字符串 而不是 json对象 可以用 JSON.stringify(data) 把json对象转json字符串 ajax传JSON时设置的contenttype 默认值是application/x-www-form-urlencoded, 当ajax传JSON时设置的contenttype 如果是application/json或者text/json时,…

2016-10-15 11:48 · spring

srping 两种配置方式:xml 和javaConfig

xml方式传统方式 javaConfig 方式为 ben方式配置 main启动方式: xml: String paths[] = {"spring-context.xml"}; ApplicationContext ctx = new ClassPathXmlApplicationContext(paths); javaConfig: AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(AppContext.class); AppContext.class 为spring 配置ben …

2015-12-28 12:02 · spring

关于Spring中的<context:annotation-config/>配置

使用@Autowired注解,必须事先在Spring容器中声明AutowiredAnnotationBeanPostProcessor的Bean: <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor "/> 使用 @Required注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean: <bean class="org.springframework.beans.factory.annotation.Requir…

2015-12-26 16:26 · spring · Spring 配置 · @Autowired

srping mvc 日期类型 注入Date 解决--@DatetimeFormat

一、时间格式注入 因为springMVC没有提供默认的日期转换器,前段页面传递过来日期字符串怎么转换为日期类型,如果没有提供全局日期转换器或者数据绑定的基础上,可以使用@DatetimeFormat注解完成 放在seter上 @Column(name = "BIRTHDAY", length = 10) public Date getBirthday() { return this.birthday; } @DateTimeFormat(pattern="yyyy-MM-dd") public void setBirthday(Date birthday) { this.birthday =…

2015-10-28 14:55 · spring

spring mvc 返回json 乱码解决

SpringMVC的@ResponseBody注解可以将请求方法返回的对象直接转换成JSON对象,但是当返回值是String的时候,中文会乱码 原因是因为其中字符串转换和对象转换用的是两个转换器,而String的转换器中固定了转换编码为"ISO-8859-1" 解决办法: 1.返回字符串时,将字符串结果转换 return new String("你好".getBytes(), "ISO-8859-1"); 2.添加@RequestMapping注解,配置produces的值 @RequestMapping(value = "/get", produces = {"application/js…

2015-10-15 10:50 · spring

spring 动态代理 ,事务管理相关

spring对AOP的支持 *如果目标对象实现了接口,默认情况下会采用JDK的动态代理实现AOP * 如果目标对象实现了接口,可以强制使用CGLIB实现AOP *如果目标对象没有实现了接口,必须采用CGLIB库,spring会自动在JDK动态代理和CGLIB之间转换 如何强制使用CGLIB实现AOP? * 添加CGLIB库,SPRING_HOME/cglib/*.jar * 在spring配置文件中加入<aop:aspectj-autoproxy proxy-target-class="true"/>或 <aop:config proxy-target-class="true"> CGLib…

2015-09-08 15:02 · spring