Java教程

idea 创建SpringBoot工程(初稿

本文主要是介绍idea 创建SpringBoot工程(初稿,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

SpringBoot工程的创建(idea)

 

框架

 

实体类Bank

public class Bank {
    private  int id;
    private  String name;
    private  int money;
​
    public int getId() {
        return id;
    }
​
    public void setId(int id) {
        this.id = id;
    }
​
    public String getName() {
        return name;
    }
​
    public void setName(String name) {
        this.name = name;
    }
​
    public int getMoney() {
        return money;
    }
​
    public void setMoney(int money) {
        this.money = money;
    }
}

BankDAO

public interface BankDAO {
    public List<Bank> findAll();
    public void insertBank(Bank bank);
    public void deleteBank(int id);
    public void updateBank(Bank bank);
}

BankCtrl

@RestController
public class BankCtrl {
    @Resource
    private BankService bankservice;
    @RequestMapping("/all")
    public List<Bank> find(){
        return bankservice.fall();
    }
    @RequestMapping("/save")
    public String save(@RequestBody Bank bank){
        bankservice.save(bank);
        return "ok";
    }
    @RequestMapping("/del")
    public String del(int uid){
        bankservice.del(uid);
        return "ok";
    }
    @RequestMapping("/update")
    public String up(@RequestBody Bank bank){
        bankservice.update(bank);
        return "ok";
    }
​
}

BankService

@Service
public class BankService {
    @Resource
    private BankDAO bdao;
    public List<Bank> fall(){
        return bdao.findAll();
    }
    public void save(Bank bank){
        bdao.insertBank(bank);
    }
    public void del (int uid){
        bdao.deleteBank(uid);
    }
    public void update(Bank bank){
        bdao.updateBank(bank);
    }
}

Application

@SpringBootApplication
@MapperScan("com.njbdqn.myspb.dao")
public class MyspbApplication {
​
    public static void main(String[] args) {
        SpringApplication.run(MyspbApplication.class, args);
    }
​
}

bank.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC
        "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njbdqn.myspb.dao.BankDAO" >
    <select id="findAll" resultType="bank">
        select * from bank
    </select>
    <insert id="insertBank" parameterType="bank">
        insert into bank values(#{id},#{name},#{money})
    </insert>
    <delete id="deleteBank" parameterType="int">
        delete from bank where id=#{id}
    </delete>
    <update id="updateBank" parameterType="bank">
        update bank
        <set>
            <if test="name !=null">
                name=#{name},
            </if>
            <if test="money !=0">
                money=#{money}
            </if>
        </set>
        <where>
            <if test="id !=0">
                id=#{id}
            </if>
        </where>
    </update>
​
</mapper>

ps 内容快速生成方法

 

application.properties改为application.yml

spring:
  datasource:
    driver-class-name: oracle.jdbc.driver.OracleDriver
    url: jdbc:oracle:thin:@192.168.100.151:1521:orcl
    username: cjy1
    password: oracle
mybatis:
  mapper-locations: classpath*:mapper/*.xml
  type-aliases-package: com.nj.myspb.entity

这篇关于idea 创建SpringBoot工程(初稿的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!