我的架构是 springBoot(1.5.9)+myBatis ,连接池用的是阿里的druid,以下是配置信息:
启动类:
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import com.github.pagehelper.PageHelper;
/**
@author wangxufei
*
*/
@SpringBootApplication
@EnableAutoConfiguration
@MapperScan("com.mofangge.mapper")
public class MfgAgencyApplication {
@Value("${spring.datasource.username}")
private String userName;
@Value("${spring.datasource.password}")
private String password;
@Value("${spring.datasource.url}")
private String url;
@Bean
public ServletRegistrationBean druidServletRegistrationBean() {
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();
servletRegistrationBean.setServlet(new StatViewServlet());
servletRegistrationBean.addUrlMappings("/druid/*");
return servletRegistrationBean;
}
/**
/**
@Bean
public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(druidDataSource());
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mybatis/*.xml"));
sqlSessionFactoryBean.setTypeAliasesPackage("com.mofangge.model,com.mofangge.dto");
Interceptor[] interceptors = {new PageHelper()};
sqlSessionFactoryBean.setPlugins(interceptors);
return sqlSessionFactoryBean.getObject();
}
public static void main(String[] args) {
SpringApplication.run(MfgAgencyApplication.class, args);
}
}
properties文件:
#server
#server.port=8080
server.port=8081
#server.port=8099
#server.servlet-path=/agency
logging.level.org.springframework.web: error
logging.level.com.mofangge:info
logging.file:mfg-agency.log
spring.data.jpa.repositories.enabled=true
spring.jpa.database=mysql
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.generate-ddl=false
spring.jpa.hibernate.ddl-auto=none
spring.jpa.open-in-view=true
spring.jpa.show-sql=false
现在遇到的问题是:
实体类中的格式 返回到页面后,字段格式变化了,如下图:
实体:
数据库:
返回到页面后的值(controller注解了@RestController):
第二个字母 应该是大写C 结果变成了小写c。
而且有个现象是:
如果你的字段是 sName 那么前端拿到的是sname
如果你的字段是seName 那么前端拿到的就是seName 不会变化
也就是说 如果驼峰前字母是2个或2个以上 他就按照原来的格式了,不知道具体是什么原因,求大佬教导。
ps:
我试过很多种方法,只有一种有效果 就是给字段注解 @JsonProperty
但是这种方法会造成我的返回值里会有2个 sname 一个是sname 一个是sName 2个字段都是同样的值 给我一种复制的感觉。。
我找到了两个回答,应该能说明你这个问题的,你看下:
http://blog.csdn.net/baggio7095586/article/details/6149768
http://blog.csdn.net/fenyuduanchangren/article/details/72964596
你可以把get/set方法改成这样子的试一试: getsName/setsName
http://blog.csdn.net/lxg2015/article/details/71404469
能看看你controller对应方法的代码吗?
http://blog.csdn.net/amo_lt/article/details/78843024
一般情况下,属性的命名不应该使用第二个字母大写的方式,你可以看看你的getter/sertter方法就知道问题所在了,,
I'm sorry 我觉得你应该好好看看java的命名规范:
javabean命名要避免第二个字母大写,否在set,get的时候 它会有问题,会映射不上。反正各种问题,
拿走不谢^_^