zoukankan      html  css  js  c++  java
  • springBoot+Vue搭建新项目(1)

    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

  • 相关阅读:
    IntelliJ IDEA生成 Serializable 序列化 UID 的快捷键
    spring boot rabbitmq 多MQ配置 自动 创建 队列 RPC
    JAVA使用并行流(ParallelStream)时要注意的一些问题
    深入浅出Stream和parallelStream
    JAVA8 十大新特性详解
    redis客户端连接,最大连接数查询与设置
    如何在Java 8中愉快地处理日期和时间
    Jenkins:使用Git Parameter插件实现tag或分支的选择性构建
    Java正确获取客户端真实IP方法整理
    redis问题接囧办法及经验
  • 原文地址:https://www.cnblogs.com/lcxz/p/14601509.html
Copyright © 2011-2022 走看看