目录
在临朐等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站设计制作、网站设计 网站设计制作按需求定制设计,公司网站建设,企业网站建设,品牌网站建设,营销型网站建设,成都外贸网站制作,临朐网站建设费用合理。1.导入相关依赖
2.创建工程结构
3. jdbc.properties属性文件
4.Spring整合Mybatis
5. Spring整合SpringMVC
6.ServletConfig配置类,加载SpringMvcConfig和SpringConfig配置类
org.springframework spring-jdbc5.2.10.RELEASE org.mybatis mybatis3.5.6 org.mybatis mybatis-spring1.3.0 mysql mysql-connector-java5.1.47 com.alibaba druid1.1.16 javax.servlet javax.servlet-api4.0.1 provided org.springframework spring-webmvc5.2.10.RELEASE com.fasterxml.jackson.core jackson-databind2.9.0 org.springframework spring-test5.2.10.RELEASE junit junit4.12 test
2.创建工程结构3. jdbc.properties属性文件jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/spring_db
jdbc.username=root
jdbc.password=root
4.Spring整合Mybatis1)JdbcConfig配置类
@Configuration
public class JdbcConfig {
@Value("${jdbc.driver}")
private String driver;
@Value("${jdbc.url}")
private String url;
@Value("${jdbc.username}")
private String username;
@Value("${jdbc.password}")
private String password;
//配置连接池
@Bean
public DataSource dataSource(){
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(driver);
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
return dataSource;
}
//Spring事务管理需要的平台事务管理器对象
@Bean
public PlatformTransactionManager transactionManager(DataSource dataSource){
DataSourceTransactionManager ds = new DataSourceTransactionManager();
ds.setDataSource(dataSource);
return ds;
}
}
2)MybatisConfig配置类
@Configuration
public class MybatisConfig {
@Bean
public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource){
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
factoryBean.setDataSource(dataSource);
factoryBean.setTypeAliasesPackage("com.ucloud.domain");
return factoryBean;
}
@Bean
public MapperScannerConfigurer mapperScannerConfigurer(){
MapperScannerConfigurer msc = new MapperScannerConfigurer();
msc.setBasePackage("com.ucloud.mapper");
return msc;
}
}
3)SpringConfig配置类,整合JdbcConfig配置类,MybatisConfig配置类
@Configuration
@ComponentScan({"com.ucloud"})
@PropertySource("classpath:jdbc.properties")
@Import({JdbcConfig.class,MybatisConfig.class})
@EnableTransactionManagement//开启事务管理
public class SpringConfig {
}
5. Spring整合SpringMVC1)SpringMvcConfig配置类
@Configuration
@ComponentScan("com.ucloud.controller")
@EnableWebMvc
public class SpringMvcConfig {
}
6.ServletConfig配置类,加载SpringMvcConfig和SpringConfig配置类 public class ServletConfig extends AbstractAnnotationConfigDispatcherServletInitializer{
protected Class>[] getRootConfigClasses() {
return new Class[]{SpringConfig.class};
}
protected Class>[] getServletConfigClasses() {
return new Class[]{SpringMvcConfig.class};
}
protected String[] getServletMappings() {
return new String[]{"/"};
}
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧