springboot创建
目录结构:
代码展示:
usercontroller:
import com.lcxz.cusunny.model.User; import com.lcxz.cusunny.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; @Controller @RequestMapping(value = "/User") public class UserController { @Autowired UserService userService; @GetMapping("/allUser") public ResponseEntity<?> findAllUser(){ Iterable<User> allUser = userService.findAllUser(); return new ResponseEntity<>(allUser, HttpStatus.CREATED); } }
UserRepository(使用的是jpa)
import com.lcxz.cusunny.model.User; import org.springframework.data.jpa.repository.JpaRepository; public interface UserRepository extends JpaRepository<User,Integer> { }
User
import javax.persistence.Entity; import javax.persistence.Id; /** * the model for database table :user */ @Entity public class User { @Id private long id; private String name; private long age; private String sex; //get/set }
UserServiceImpl
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class UserServiceImpl implements UserService { @Autowired UserRepository userRepository; @Override public List<User> findAllUser(){ List<User> all = userRepository.findAll(); return all; } }
UserService
import org.springframework.stereotype.Service; @Service public interface UserService { public Iterable<User> findAllUser(); }
application
server: port: 8880 spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver username: root password: root url: jdbc:mysql://localhost:3306/cusunny jpa: show-sql: true
springboot搭建ok
vue项目的创建:
环境安装略,网上很多
项目初始化:
检查vue-cli是否安装:vue list ;安装命令:cnpm install vue-cli -g
打开或者cd到保存vue项目的文件夹。cmd
创建项目:vue init webpack ”项目名称“;例 vue init webpack abcd-ui
按提示进行选择y/n,(以下三个建议为no,减少一些没有必要的报警信息)
创建好后:
安装:cnpm install(不用每次都install)
运行:cnpm run dev
vue搭建ok