在DemoTestApplication启动项上加上@RestController,写一个hi方法,路径也是hi,返回当前时间
在游览器输入localhost:8080/hi,确实返回当前时间了,没问题!
接着写Controller,@RequestMapping上加上路径User,同样写一个测试test,和上一步相同,输入localhost:8080/User/test,游览器返回test。在写一个findall查询所有用户。
UserService接口中有findall方法。
在UserService的实现类UserServiceI中,调用UserManagerger的findAll方法,继续踢皮球
皮球来到UserManager接口这边,让他的实现类来干活吧。
把mongodbTemplate拉来干活,返回User列表。稍微复杂一点的操作findbyname继续踢给UserDao做。
UserDao和UserManager整体差不多,都是接口揽活,实现类做事。
接口和实现类都要记得加@Repository注解,不然找不到bean。private MongoTemplate mongoTemplate上要加@Autowired,不然mongoTemplate会为报错null。
游览器输入localhost:8080/User/findall,成功查到数据,卧槽我是天才吗。