這是接着上一篇寫的,在上一篇的基礎上添加java
Controllerspring
@RestController public class HelloController { @Resource private HelloService helloService; @RequestMapping("/hello") public String hello(){ return "hello"; } @RequestMapping("/saveUser") public String user(){ User u = new User(); u.setPassword("1"); u.setUser_name("123"); u.setAge(1); helloService.saveUser(u); return "success"; } }
Serviceapp
import org.springframework.stereotype.Service; import javax.annotation.Resource; /** * Created by Administrator on 2017/5/27 0027. */ @Service public class HelloService { @Resource private HelloDao helloDao; public void saveUser(User u) { helloDao.save(u); } }
Dao(接口,實現了CrudRepository<User,Long>)spa
public interface HelloDao extends CrudRepository<User,Long>{ }
而後運行項目,輸入:http://localhost:8080/saveUsercode
表中會多了blog
一條記錄接口