嘻哈飞车族|SpringBoot:数据库访问之Mybatis( 二 )

5 修改属性配置文件
#jdbc信息spring.datasource.username=rootspring.datasource.password=123456spring.datasource.driver-class-name=com.mysql.jdbc.Driverspring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf-8}}7 创建访问的controller
@RestControllerpublic class MybatisDemoController {@Autowiredprivate DemoService demoService;@RequestMapping(value="http://kandian.youth.cn/save", method=RequestMethod.POST)public String save(@RequestParam("name") String name, @RequestParam("telphone") String telphone){DemoEntity entity = new DemoEntity();entity.setName(name);entity.setTelphone(telphone);int result = demoService.save(entity);return String.valueOf(result);}@RequestMapping(value="http://kandian.youth.cn/get", method=RequestMethod.GET)public String getById(@RequestParam("id") Integer id){DemoEntity entity = demoService.selectById(id);return entity.toString();}@RequestMapping(value="http://kandian.youth.cn/delete", method=RequestMethod.POST)public String delete(@RequestParam("id") Integer id){int result = demoService.deleteById(id);return String.valueOf(result);}@RequestMapping(value="http://kandian.youth.cn/update", method=RequestMethod.POST)public String update(DemoEntity entity){demoService.updateDemoEntity(entity);return "success";}}启动服务后 , 即可访问测试 。


推荐阅读