引用百度百科:
<dependency>
<groupId>org.mariadb.jdbcgroupId>
<artifactId>mariadb-java-clientartifactId>
dependency>
<dependency>
<groupId>com.alibabagroupId>
<artifactId>druidartifactId>
dependency>
<dependency>
<groupId>com.hsy.javagroupId>
<artifactId>java-beanartifactId>
dependency>
<dependency>
<groupId>org.mybatis.spring.bootgroupId>
<artifactId>mybatis-spring-boot-starterartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starterartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
TExerciseZoneMapper.java
public interface TExerciseZoneMapper {
List selectAll(@Param(value = "offset") Integer offset, @Param(value = "limit") Integer limit) ;
int update(@Param(value = "parentId") Integer parentId,@Param(value = "id") Long id) ;
}
mapper文件
<mapper namespace="com.hsy.springboot.mybatis.mapper.TExerciseZoneMapper">
<select id="selectAll" resultType="TExerciseZone">
select * from t_exercise_zone_test where 1 = 1 limit #{offset} , #{limit};
select>
<select id="getProvinceById" resultType="TExerciseZone">
select * from t_exercise_zone_test WHERE 1 = 1
<if test="id!=null || ''!=id">
AND id = #{id}
if>
select>
<update id="update">
update t_exercise_zone_test set parent_id = #{parentId} WHERE id = #{id}
update>
mapper>
@Service(value = "exerciseZoneService")
public class TExerciseZoneServiceImpl implements ITExerciseZoneService{
@SuppressWarnings("SpringJavaAutowiringInspection")
@Autowired private TExerciseZoneMapper tExerciseZoneMapper ;
@Override
public List getAll(Integer offset,Integer limit) {
return tExerciseZoneMapper.selectAll(offset,limit);
}
@Transactional
@Override
public Boolean update(Integer parentId,Long id) {
tExerciseZoneMapper.update(100000,1l) ;
int i = 1 / 0 ;
tExerciseZoneMapper.update(110000,2l) ;
return true;
}
}
@RestController
@RequestMapping("/api/rest")
public class RestfulController extends BaseController{
@Autowired private ITExerciseZoneService exerciseZoneService ;
@RequestMapping(value = "/update/{id}",method = RequestMethod.PUT,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseBodyBean update(@PathVariable Long id,@RequestParam Integer parentId){
return success(exerciseZoneService.update(parentId,id)) ;
}
@GetMapping(value = {"/v1/zones/{offset}/{limit}"})
public ResponseBodyBean> zoneList(@PathVariable Integer offset, @PathVariable Integer limit){
return success(exerciseZoneService.getAll(offset,limit)) ;
}
}
server.port=9527
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.url=jdbc:mariadb://192.168.175.128:3306/exercise?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=root@mariadb
mybatis.mapper-locations=classpath*:mybatis/*Mapper.xml
mybatis.type-aliases-package=com.hsy.java.bean.po
@SpringBootApplication
@MapperScan("com.hsy.springboot.mybatis.mapper")
public class SpringBootMybatisApplication {
public static void main(String[] args){
SpringApplication.run(SpringBootMybatisApplication.class,args) ;
}
}
springboot-mybatis
SpringBoot实战之入门
springboot实战之文章汇总
springboot实战之读取配置文件
springboot实战之整合jsp模版引擎
springboot实战之整合freemarker模版引擎
springboot实战之注册自定义Servlet
springboot实战之注册filter和listener
springboot实战之注册interceptor
springboot实战之整合slf4j日志系统
springboot实战之整合CommandLineRunner
springboot实战之整合restful工具swagger2
springboot实战之整合jdbc进行crud操作