⾸先
在启动类XxxxApplication类⾥⾯,添加使⽤@mapper注解的包进⾏扫描:
在resources⾥⾯新建mapper⽂件夹存放l映射⽂件
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE mapper PUBLIC "-////DTD Mapper 3.0//EN" "/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.springbootcache.mapper.UserDao " >
<select id="getUserById" resultType="com.springbootcache.domain.User">
"SELECT * FROM tb_user WHERE id=#{id}
</select>
</mapper>
还有在application.properties配置⽂件⾥⾯
#映射表
mybatis.mapper-locations=classpath:mapper/*.xml
下⾯是缺少的代码
domain包下(pojo):
@Data
public class User implements Serializable {
private Integer id;
private String name;
private int age;
}
controller包下(负责与⽤户进⾏交互):
@RestController
public class UserController {
@Autowired
UserService userService;
@GetMapping("/user/{id}")
public User getUserById(@PathVariable("id") Integer id){
UserById(id);
}
}
config包下(这⾥配置了swagger接⼝⽂档):
有兴趣可以了解⼀下swagger2技术,很简单的,有以注解的⽅式。
package fig;
import t.annotation.Bean;
import t.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket docket(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
/
/RequestHandlerSelectors,配置要扫描接⼝的⽅式
//basePackage("ller"),配置要扫描的包
//any(),扫描全部
//none(),什么都不扫描
//withMethodAnnotation(GetMapping.class),扫描⽅法上的注解,[GetMapping/RequestMapping/PostMapping] //withClassAnnotation(),扫描类上的注解
.apis(RequestHandlerSelectors.basePackage("ller"))
//paths(),过滤什么路径
// .paths(PathSelectors.ant("/springbootcache/**"))
.build();
}
private ApiInfo apiInfo() {
//作者信息
Contact contact=new Contact("lee","blog.csdn/weixin_43849543","xxxx@qq");
springboot结构return new ApiInfo(
"lee的API⽂档",
"相逢太短,不等茶凉。",
"1.0",
"blog.csdn/weixin_43849543",
contact,
"Apache 2.0",
"/licenses/LICENSE-2.0",
new ArrayList());
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论