1 配置文件 application.properties #server server.port=8090 server.address=127.0.0.1 server.session.timeout=1800 server.error.whitelabel.enabled=true #mybatis mybatis.config-locations=classpath:mybatis/mybatis-config.xml // mybatis配置文件 mybatis.mapper-locations=classpath:mybatis/mapper/*.xml //mapper映射文件
mybatis-config.xml
BaseMapper.xmlinsert into ${table} ${item1} values#{item2} insert into ${table} ${item} values#{item} update ${table} set ${item} = #{columnvalues[${item}]} 1=1 ${item} #{val} delete from ${table} 1=1 ${item} #{val} delete from ${table} ${idkey} in #{item}
pom.xml4.0.0 com.example smalldemo 2 war SpringBootDemo Demo project for Spring Boot org.springframework.boot spring-boot-starter-parent 1.5.4.RELEASE UTF-8 UTF-8 1.7 org.springframework.boot spring-boot-starter-redis 1.4.7.RELEASE org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.0 org.springframework.boot spring-boot-starter-web com.alibaba fastjson 1.2.16 com.alibaba druid-spring-boot-starter 1.1.2 mysql mysql-connector-java runtime org.springframework.boot spring-boot-starter-test test com.caucho hessian 4.0.38 org.springframework.boot spring-boot-starter-tomcat provided com.github.wxpay wxpay-sdk 0.0.3 org.apache.httpcomponents httpclient 4.5.3 net.sourceforge.htmlunit htmlunit org.springframework.boot spring-boot-maven-plugin
Application.java/** * 项目启动类 * spring boot application只会扫描同一包下的类 * @author sys * */@SpringBootApplication@EnableAutoConfiguration(exclude = { JacksonAutoConfiguration.class })@ServletComponentScan@EnableTransactionManagement //加入事务注解@MapperScan("com.sys.mapper")public class Application extends SpringBootServletInitializer{ //fastkson @Bean public HttpMessageConverters fastJsonHttpMessageConverters() { FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); fastConverter.setFastJsonConfig(fastJsonConfig); HttpMessageConverter converter = fastConverter; return new HttpMessageConverters(converter); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); } public static void main(String[] args) { SpringApplication.run(Application.class, args); }}
下篇继续--java对mybatis的curd封装
要源码的联系 qq 2506715686