码迷,mamicode.com
首页 > 其他好文 > 详细

新建一个maven工程

时间:2017-06-29 11:27:50      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:mil   org   long   save   update   depend   nap   repo   his   

软件151  徐中飞

 

 

使用spring boot新建maven工程不在需要建立maven web工程,只要一般的maven工程就好了。 
二、maven包的导入 
清单如下:

<!-- Inherit defaults from Spring Boot -->

  <parent>

  <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-parent</artifactId>

        <version>1.3.1.BUILD-SNAPSHOT</version>

  </parent>

 

<!-- Add typical dependencies for a web application -->

    <dependencies>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>

 

        <!-- spring data jpa -->

        <dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-data-jpa</artifactId>

</dependency>

 

<!-- mysql driver -->

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

</dependency>

        <!-- 其他依赖 -->

        <dependency>

<groupId>javax.persistence</groupId>

<artifactId>persistence-api</artifactId>

<version>1.0.2</version>

</dependency>

    </dependencies>

 

    <!-- Package as an executable jar -->

    <build>

        <plugins>

            <plugin>

                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-maven-plugin</artifactId>

            </plugin>

            <!-- 编译器版本指定 -->

            <plugin> 

        <groupId>org.apache.maven.plugins</groupId> 

        <artifactId>maven-compiler-plugin</artifactId> 

        <configuration> 

          <source>1.7</source> 

          <target>1.7</target> 

        </configuration> 

      </plugin> 

        </plugins>

    </build>

 

    <!-- Add Spring repositories -->

    <pluginRepositories>

        <pluginRepository>

            <id>spring-snapshots</id>

            <url>http://repo.spring.io/snapshot</url>

        </pluginRepository>

        <pluginRepository>

            <id>spring-milestones</id>

            <url>http://repo.spring.io/milestone</url>

        </pluginRepository>

    </pluginRepositories>

 

    <repositories>

        <repository>

            <id>spring-snapshots</id>

            <url>http://repo.spring.io/snapshot</url>

            <snapshots><enabled>true</enabled></snapshots>

        </repository>

        <repository>

            <id>spring-milestones</id>

            <url>http://repo.spring.io/milestone</url>

        </repository>

</repositories>



3.4.2代码实现

(1)、创建实体类

package com.whucker.platform.domain;

@Entity //实体

@Table(name="t_user") //指定表名

public class User {

    @Id //定义主键id

    @GeneratedValue(strategy=GenerationType.AUTO) //自增

    private Long id;

    private String name;

    private int age;

    private int gender;

    //...此处省略get/set

}

(2)、Repository代码(package com.whucker.platform.repository;

 

public interface UserRepository extends CrudRepository<User, Long>{

}

 

3.4.3业务层

(1)接口定义

package com.whucker.platform.service;

public interface IUserService {

    //添加

    void save(User user);

    //删除

    void delete(Long id);

    //修改

    void update(User user);

    //查询单个对象

    User findOne(Long id);

    //查询所有

    List<User> findAll();

}

(2)接口实现

package com.whucker.platform.service.impl;

 

@Service(value="userService")

@Transactional

public class UserServiceImpl implements IUserService{

 

    @Autowired

    private UserRepository userRepository;

 

    @Override

    public void save(User user) {

        this.userRepository.save(user);

    }

   

}

3.4.4控制层

package com.whucker.platform.controler;

@RestController

public class IndexManageAction {

    @RequestMapping(value="/")

    public String index(){

        return "欢迎访问首页!";

    }

}

 

3.4.5Application类

package com.whucker.platform;

@SpringBootApplication

public class Application {

    public static void main(String[] args) {

        SpringApplication.run(Application.class);

}

新建一个maven工程

标签:mil   org   long   save   update   depend   nap   repo   his   

原文地址:http://www.cnblogs.com/xzf9/p/7093168.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!