一、bean/entity/domain
package com.example.demo.bean;
public class Hero {
private String id;
private String heroName;
private Integer heroCost;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getHeroName() {
return heroName;
}
public void setHeroName(String heroName) {
this.heroName = heroName;
}
public Integer getHeroCost() {
return heroCost;
}
public void setHeroCost(Integer heroCost) {
this.heroCost = heroCost;
}
}
二、mapper
package com.example.demo.mapper;
import com.example.demo.bean.Hero;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface HeroMapper {
@Select("select * from hero")
public List<Hero> getAll();
}
三、controller
package com.example.demo.controller;
import com.example.demo.bean.Hero;
import com.example.demo.mapper.HeroMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class HeroController {
@Autowired
private HeroMapper heroMapper;
@RequestMapping("/getAll")
public List<Hero> getAll(){
return heroMapper.getAll();
}
}
四、application
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class,args);
}
}
五、vue
<template>
<div class="home">
<el-row v-for="hero in heroList">
<el-card>
<div>{{hero.heroName}}</div>
</el-card>
</el-row>
</div>
</template>
<script>
export default {
data() {
return {
heroList: [],
}
},
methods:{
getHero(){
this.axios.get("http://localhost:8080/getAll").then(response=>{
this.heroList=response.data
})
// .catch(error=>{
// console.error(error);
// this.$message.error(error);
// })
}
},
created(){
this.getHero()
}
}
</script>
3万+

被折叠的 条评论
为什么被折叠?



