我的架构是 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;
}/**
- 注册DruidFilter拦截
- @return / @Bean public FilterRegistrationBean duridFilterRegistrationBean() { FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); filterRegistrationBean.setFilter(new WebStatFilter()); Map initParams = new HashMap(); // 设置忽略请求 initParams.put("exclusions", ".js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"); filterRegistrationBean.setInitParameters(initParams); filterRegistrationBean.addUrlPatterns("/*"); return filterRegistrationBean; }
/**
- 配置DruidDataSource
- @return
- @throws SQLException */ @Bean public DruidDataSource druidDataSource() throws SQLException { DruidDataSource druidDataSource = new DruidDataSource(); druidDataSource.setUsername(userName); druidDataSource.setPassword(password); druidDataSource.setUrl(url); druidDataSource.setMaxActive(100); druidDataSource.setFilters("stat,wall"); druidDataSource.setInitialSize(10); return druidDataSource; }
@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
log
logging.level.org.springframework.web: error
logging.level.com.mofangge:info
logging.file:mfg-agency.log
JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
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个字段都是同样的值 给我一种复制的感觉。。