栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot

##springboot整合mybaitis
添加依赖:pom.xml

	
		
			org.springframework.boot
			spring-boot-starter-web
		
         
		
			org.springframework.boot
			spring-boot-starter-test
			test
		

		
			org.springframework.boot
			spring-boot-configuration-processor
			true
		

		
			org.springframework.boot
			spring-boot-starter-thymeleaf
		

		
			mysql
			mysql-connector-java
		

		
			org.mybatis.spring.boot
			mybatis-spring-boot-starter
			2.2.2
		
		
		
			com.alibaba
			fastjson
			1.2.78
		

配置文件:application.prperties(yml)

#端口
server.port=8080
#项目根路径
server.servlet.context-path=/bootDemo
#student.age=13
#logging.level.cn.kgc.bootdemo=trace
#配置日志文件,我的是logback.xml,也可以配置其他日志文件
logging.config=classpath:logback.xml
#关闭缓存
spring.thymeleaf.cache=false
#配置数据库
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost/
spring.datasource.name=root
spring.datasource.password=root
#配置mybatis
#配置映射文件路径
mybatis.mapper-locations=classpath:mappers

    @Override
    public List getPetList() {
        return petDao.getPetList();
    }
}

Controller层:

@RestController
public class PetController {
//最好是Resource
    @Resource
    private PetService petService;
   petTypeService;
    @RequestMapping("/petlist")
    public  String getPetList(@RequestParam(required = false)String breed){
        System.out.println("品种"+breed);
        if (breed==null||breed.equals("0")){
        return JSON.toJSONString(petService.getPetList());}
        else {
            return JSON.toJSONString(petService.getPetListByTypeName(breed));
        }
    }
    }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/999829.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号