springboot+springdata jpa后端接口实现

这个是目录springboot+springdata jpa后端接口实现_第1张图片

首先导入jpa的依赖


        
            org.springframework.boot
            spring-boot-starter-data-jpa
        

 

下面的是SwaggerConfig

package com.teacher.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
        @Bean
        public Docket createRestApi() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.teacher.controller"))
                    .paths(PathSelectors.any())
                    .build();
        }
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("SWAGGER API MANAGEMENT")
                    .description("基于 Spring MVC 的 Swagger API 管理")
                    .contact(contact())
                    .version("1.0")
                    .build();
        }
        private Contact contact() {
            return new Contact("yaya", "https://www.wlgzs.net/", "[email protected]");
        }

    }

下面是properties文件的配置

# 应用名称
spring.application.name=teacher-up
# 应用服务 WEB 访问端口
server.port=8080
spring.datasource.url=jdbc:mysql://localhost:3306/teachers?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=12345678


mybatis.mapper-locations:classpath:mapper/*Dao.xml
mybatis.type-aliases-package=com.teacher.pojo
mybatis.configuration.map-underscore-to-camel-case=true

#自动生成数据库表(关键)
spring.jpa.hibernate.ddl-auto=update
#mysql数据库驱动程序(重要)
#jpa配置:在控制台显示Hibernate的sql(可选)
spring.jpa.show-sql = true

 下面的是工具类Response(从网上找的模版进行了适当修改)

package com.teacher.utils;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Response {
    // 统一结果返回类
    //标识返回的状态码
    private Integer code;
    //标识返回的信息
    private String message;
    //标识返回的数据
    private Object data;

    //私有化,防止new
    private Response() {  }
    //成功
    public static Response ok(Object data, String message) {
        return new Response(1, message, data);  //code 也可以使用字典管理 下面会谈到
    }

    //成功返回 重载 message没有特别要求
    public static Response ok(Object data) {
        return Response.ok(data, "success"); //message 也可以使用字典管理 下面会谈到
    }

    // 失败
    public static Response error(Object data, String message) {
        return new Response(-1, message, data);
    }

    public static Response error(Object data) {
        return Response.error(data,"fail");  //code 也可以使用字典管理 下面会谈到
    }


    /************************/
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Response(String message, Object data) {
        this.message = message;
        this.data = data;
    }
}

 下面的是实体类

package com.teacher.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name="teacher")
@EntityListeners(AuditingEntityListener.class)
public class Teacher {
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    @Column(name = "tea_code")
    private String teaCode;
    @Column(name = "tea_name")
    private String teaName;
    @Column(name = "tea_sex")
    private String teaSex;
    @Column(name = "tea_major")
    private String teaMajor;
    @Column(name = "tea_education")
    private String teaEducation;
    @Column(name = "tea_school")
    private String teaSchool;
    @Column(name = "tea_faculty")
    private String teaFaculty;
    @Column(name = "tea_academic")
    private String teaAcademic;
    @Column(name = "tea_data")
    private int teaData;

    public Teacher(String teaCode, String teaName, String teaSex, String teaMajor, String teaEducation, String teaSchool, String teaFaculty, String teaAcademic, int teaData) {
        this.teaCode = teaCode;
        this.teaName = teaName;
        this.teaSex = teaSex;
        this.teaMajor = teaMajor;
        this.teaEducation = teaEducation;
        this.teaSchool = teaSchool;
        this.teaFaculty = teaFaculty;
        this.teaAcademic = teaAcademic;
        this.teaData = teaData;
    }
}

下面的是dao层

package com.teacher.repository;

import com.teacher.pojo.Teacher;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface TeacherRepository extends JpaRepository, JpaSpecificationExecutor {
    @Query(value="select * from teacher where id=?",nativeQuery = true)
    Teacher queryTeaByID(int id);

    /**
     *根据姓名模糊查询
     */
    @Query(value="select * from teacher where tea_name like %?1% limit ?2,5",nativeQuery = true)
    List queryTeaByName(String teaName,int pages);

    /**
     *根据姓名模糊查询数量
     */
    @Query(value="select count(*) from teacher where tea_name like %?%",nativeQuery = true)
    int queryTeaByNameCount(String teaName);

    /**
     *根据性别模糊查询
     */
    @Query(value="select * from teacher where tea_sex like %?1% limit ?2,5",nativeQuery = true)
    List queryTeaBySex(String teaSex,int pages);

    /**
     *根据性别模糊查询数量
     */
    @Query(value="select count(*) from teacher where tea_sex like %?%",nativeQuery = true)
    int queryTeaBySex(String teaSex);

    /**
     *根据专业模糊查询
     */
    @Query(value="select * from teacher where tea_major like %?1% limit ?2,5",nativeQuery = true)
    List queryTeaByMajor(String teaMajor,int pages);

    /**
     *根据专业模糊查询数量
     */
    @Query(value="select count(*) from teacher where tea_major like %?%",nativeQuery = true)
    int queryTeaByMajor(String teaMajor);

    /**
     *根据学历模糊查询
     */
    @Query(value="select * from teacher where tea_education like %?1% limit ?2,5",nativeQuery = true)
    List queryTeaByEdu(String teaEducation,int pages);

    /**
     *根据学历模糊查询数量
     */
    @Query(value="select count(*) from teacher where tea_education like %?%",nativeQuery = true)
    int queryTeaByEdu(String teaEducation);

    /**
     *根据职称模糊查询
     */
    @Query(value="select * from teacher where tea_academic like %?1% limit ?2,5",nativeQuery = true)
    List queryTeaByAcademic(String teaAcademic,int pages);

    /**
     *根据职称模糊查询数量
     */
    @Query(value="select count(*) from teacher where tea_academic like %?%",nativeQuery = true)
    int queryTeaByAcademic(String teaAcademic);

    /**
     *根据毕业院校模糊查询
     */
    @Query(value="select * from teacher where tea_school like %?1% limit ?2,5",nativeQuery = true)
    List queryTeaBySchool(String teaSchool,int pages);

    /**
     *根据毕业院校模糊查询数量
     */
    @Query(value="select count(*) from teacher where tea_school like %?%",nativeQuery = true)
    int queryTeaBySchool(String teaSchool);

    /**
     *根据所在院系模糊查询
     */
    @Query(value="select * from teacher where tea_faculty like %?1% limit ?2,5",nativeQuery = true)
    List queryTeaByFaculty(String teaFaculty,int pages);

    /**
     *根据所在院系模糊查询数量
     */
    @Query(value="select count(*) from teacher where tea_faculty like %?%",nativeQuery = true)
    int queryTeaByFaculty(String teaFaculty);

    /**
     *分页查询全部教师
     */
    @Query(value="select * from teacher limit ?1,?2",nativeQuery = true)
    List queryTeaByPage(int pages, int num);

    /**
     *分页查询全部教师数量
     */
    @Query(value="select count(*) from teacher",nativeQuery = true)
    int queryTeaByPageCount();

    /**
     * 模糊查询数量
     */
    @Query(value = "select count(*) from teacher where concat(tea_name,tea_sex,tea_major,tea_education,tea_academic,tea_school,tea_faculty) like concat('%',?1,'%')", nativeQuery = true)
    int queryConcatCount(@Param("thing") String thing);

    /**
     * 模糊查询
     */
    @Query(value = "select * from teacher where concat(tea_name,tea_sex,tea_major,tea_education,tea_academic,tea_school,tea_faculty) like concat('%',?1,'%') limit ?2,5", nativeQuery = true)
    List queryConcat(@Param("thing") String thing,@Param("pages")int pages);
}

 下面的是Service层

package com.teacher.service;

import com.teacher.pojo.Teacher;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

public interface TeacherService {
    /**
     * 增加老师
     */
    Teacher insertTeacher(Teacher teacher);

    /**
     * 删除老师
     */
    void deleteTeacher(int id);

    /**
     * 修改老师
     */
    Teacher updateTeacher(Teacher teacher);

    /**
     * 查询所有老师
     */
    List findAllTeacher();

    /**
     * 通过id查询老师
     */
    Teacher findTeacherById(int id);

    /**
     *分页查询全部教师
     */
    Map queryTeaByPage(int pages);

    /************************************************/
    /**
     *根据姓名模糊查询
     */
    Map queryTeaByName(String teaName,int pages);

    /**
     *根据性别模糊查询
     */
    Map queryTeaBySex(String teaSex,int pages);

    /**
     *根据专业模糊查询
     */
    Map queryTeaByMajor(String teaMajor,int pages);

    /**
     *根据学历模糊查询
     */
    Map queryTeaByEdu(String teaEducation,int pages);

    /**
     *根据职称模糊查询
     */
    Map queryTeaByAcademic(String teaAcademic,int pages);

    /**
     *根据毕业院校模糊查询
     */
    Map queryTeaBySchool(String teaSchool,int pages);

    /**
     *根据所在院系模糊查询
     */
    Map queryTeaByFaculty(String teaFaculty,int pages);

    /**
     * 模糊查询
     */
    Map queryConcat(String thing,int pages);
}

实现类

package com.teacher.service.impl;

import com.teacher.pojo.Teacher;
import com.teacher.repository.TeacherRepository;
import com.teacher.service.TeacherService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

@Service
public class TeacherServiceImpl implements TeacherService {

    @Resource
    private TeacherRepository teacherRepository;

    @Override
    public Teacher insertTeacher(Teacher teacher) {
        return teacherRepository.save(teacher);
    }

    @Override
    public void deleteTeacher(int id) {
        teacherRepository.deleteById(id);
    }

    @Override
    public Teacher updateTeacher(Teacher teacher) {
        return teacherRepository.save(teacher);
    }

    @Override
    public List findAllTeacher() {
        return teacherRepository.findAll();
    }

    @Override
    public Teacher findTeacherById(int id) {
        return teacherRepository.findById(id).orElse(null);
    }

    @Override
    public Map queryTeaByPage(int pages) {
        Map map=new HashMap<>();
        int num=5,totalPages,total;
        int count=teacherRepository.queryTeaByPageCount();
        if (count % num == 0) {
            totalPages = count / num;
        } else {
            total = count / num;
            totalPages = total + 1;
        }
        List list = new LinkedList<>();
        list.add(totalPages);
        map.put("总共的页数", list);
        List list1 = new LinkedList<>();
        list1.add(count);
        map.put("总条数", list1);
        int thePage = (pages - 1) * num;
        List list2 = teacherRepository.queryTeaByPage( thePage, num);
        map.put("查询信息", list2);
        return map;
    }

    @Override
    public Map queryTeaByName(String teaName, int pages) {
        Map map=new HashMap<>();
        int num=5,totalPages,total;
        int count=teacherRepository.queryTeaByNameCount(teaName);
        if (count % num == 0) {
            totalPages = count / num;
        } else {
            total = count / num;
            totalPages = total + 1;
        }
        List list = new LinkedList<>();
        list.add(totalPages);
        map.put("总共的页数", list);
        List list1 = new LinkedList<>();
        list1.add(count);
        map.put("总条数", list1);
        int thePage = (pages - 1) * num;
        List list2 = teacherRepository.queryTeaByName(teaName,thePage);
        map.put("查询信息", list2);
        return map;
    }

    @Override
    public Map queryTeaBySex(String teaSex, int pages) {
        Map map=new HashMap<>();
        int num=5,totalPages,total;
        int count=teacherRepository.queryTeaBySex(teaSex);
        if (count % num == 0) {
            totalPages = count / num;
        } else {
            total = count / num;
            totalPages = total + 1;
        }
        List list = new LinkedList<>();
        list.add(totalPages);
        map.put("总共的页数", list);
        List list1 = new LinkedList<>();
        list1.add(count);
        map.put("总条数", list1);
        int thePage = (pages - 1) * num;
        List list2 = teacherRepository.queryTeaBySex(teaSex,thePage);
        map.put("查询信息", list2);
        return map;
    }

    @Override
    public Map queryTeaByMajor(String teaMajor, int pages) {
        Map map=new HashMap<>();
        int num=5,totalPages,total;
        int count=teacherRepository.queryTeaByMajor(teaMajor);
        if (count % num == 0) {
            totalPages = count / num;
        } else {
            total = count / num;
            totalPages = total + 1;
        }
        List list = new LinkedList<>();
        list.add(totalPages);
        map.put("总共的页数", list);
        List list1 = new LinkedList<>();
        list1.add(count);
        map.put("总条数", list1);
        int thePage = (pages - 1) * num;
        List list2 = teacherRepository.queryTeaByMajor(teaMajor,thePage);
        map.put("查询信息", list2);
        return map;
    }

    @Override
    public Map queryTeaByEdu(String teaEducation, int pages) {
        Map map=new HashMap<>();
        int num=5,totalPages,total;
        int count=teacherRepository.queryTeaByEdu(teaEducation);
        if (count % num == 0) {
            totalPages = count / num;
        } else {
            total = count / num;
            totalPages = total + 1;
        }
        List list = new LinkedList<>();
        list.add(totalPages);
        map.put("总共的页数", list);
        List list1 = new LinkedList<>();
        list1.add(count);
        map.put("总条数", list1);
        int thePage = (pages - 1) * num;
        List list2 = teacherRepository.queryTeaByEdu(teaEducation,thePage);
        map.put("查询信息", list2);
        return map;
    }

    @Override
    public Map queryTeaByAcademic(String teaAcademic, int pages) {
        Map map=new HashMap<>();
        int num=5,totalPages,total;
        int count=teacherRepository.queryTeaByAcademic(teaAcademic);
        if (count % num == 0) {
            totalPages = count / num;
        } else {
            total = count / num;
            totalPages = total + 1;
        }
        List list = new LinkedList<>();
        list.add(totalPages);
        map.put("总共的页数", list);
        List list1 = new LinkedList<>();
        list1.add(count);
        map.put("总条数", list1);
        int thePage = (pages - 1) * num;
        List list2 = teacherRepository.queryTeaByAcademic(teaAcademic,thePage);
        map.put("查询信息", list2);
        return map;
    }

    @Override
    public Map queryTeaBySchool(String teaSchool, int pages) {
        Map map=new HashMap<>();
        int num=5,totalPages,total;
        int count=teacherRepository.queryTeaBySchool(teaSchool);
        if (count % num == 0) {
            totalPages = count / num;
        } else {
            total = count / num;
            totalPages = total + 1;
        }
        List list = new LinkedList<>();
        list.add(totalPages);
        map.put("总共的页数", list);
        List list1 = new LinkedList<>();
        list1.add(count);
        map.put("总条数", list1);
        int thePage = (pages - 1) * num;
        List list2 = teacherRepository.queryTeaBySchool(teaSchool,thePage);
        map.put("查询信息", list2);
        return map;
    }

    @Override
    public Map queryTeaByFaculty(String teaFaculty, int pages) {
        Map map=new HashMap<>();
        int num=5,totalPages,total;
        int count=teacherRepository.queryTeaByFaculty(teaFaculty);
        if (count % num == 0) {
            totalPages = count / num;
        } else {
            total = count / num;
            totalPages = total + 1;
        }
        List list = new LinkedList<>();
        list.add(totalPages);
        map.put("总共的页数", list);
        List list1 = new LinkedList<>();
        list1.add(count);
        map.put("总条数", list1);
        int thePage = (pages - 1) * num;
        List list2 = teacherRepository.queryTeaByFaculty(teaFaculty,thePage);
        map.put("查询信息", list2);
        return map;
    }

    @Override
    public Map queryConcat(String thing, int pages) {
        Map map=new HashMap<>();
        int num=5,totalPages,total;
        int count=teacherRepository.queryConcatCount(thing);
        if (count % num == 0) {
            totalPages = count / num;
        } else {
            total = count / num;
            totalPages = total + 1;
        }
        List list = new LinkedList<>();
        list.add(totalPages);
        map.put("总共的页数", list);
        List list1 = new LinkedList<>();
        list1.add(count);
        map.put("总条数", list1);
        int thePage = (pages - 1) * num;
        List list2 = teacherRepository.queryConcat(thing,thePage);
        map.put("查询信息", list2);
        return map;
    }


}

 下面的是controller层

package com.teacher.controller;

import com.teacher.pojo.Teacher;
import com.teacher.service.TeacherService;
import com.teacher.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api(tags = "teacher")
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Resource
    private TeacherService teacherService;

    /**
     * 增加老师
     */
    @ApiOperation(value = "增加老师")
    @PostMapping("/addTeacher")
    @ResponseBody
    public Teacher addTeacher(String code,String name,String sex,String major,String education,String school,String faculty,String academic,int data){
        Teacher teacher=new Teacher(code,name,sex,major,education,school,faculty,academic,data);
        return teacherService.insertTeacher(teacher);
    }

    /**
     * 删除老师
     */
    @DeleteMapping("/deleteTeacher")
    @ApiOperation(value = "删除老师")
    @ResponseBody
    public Response deleteUser(int id){
        teacherService.deleteTeacher(id);
        return Response.ok("success!");
    }

    /**
     * 修改老师
     */
    @PutMapping("/updateTeacher")
    @ApiOperation(value = "修改老师")
    @ResponseBody
    public Response updateTeacher(Teacher teacher){
        teacherService.updateTeacher(teacher);
        return Response.ok("success!");
    }

    /**
     * 查询所有老师
     */
    @GetMapping("/findAll")
    @ApiOperation(value = "查询所有老师")
    @ResponseBody
    public List findAll(){
         return teacherService.findAllTeacher();
    }

    /**
     * 通过id查询老师
     */
    @GetMapping("/findTeacherById")
    @ApiOperation(value = "通过id查询老师")
    @ResponseBody
    public Teacher findByIdyId(int id){
        return teacherService.findTeacherById(id);
    }

    /**
     * 分页查询
     */
    @GetMapping("/pageTest")
    @ApiOperation(value = "分页查询(一页五条)")
    @ResponseBody
    public Map find(int pages){
        return teacherService.queryTeaByPage(pages);
    }

    /****************************************/
    /**
     *根据姓名模糊查询
     */
    @GetMapping("/queryTeaByName")
    @ApiOperation(value = "根据姓名模糊查询")
    @ResponseBody
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "teaName", value = "姓名", required = true),
                    @ApiImplicitParam(name = "pages", value = "第几页", required = true),
            }
    )
    public Map queryTeaByName(String teaName,int pages){
        return teacherService.queryTeaByName(teaName,pages);
    }

    /**
     *根据性别模糊查询
     */
    @GetMapping("/queryTeaBySex")
    @ApiOperation(value = "根据性别模糊查询")
    @ResponseBody
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "teaSex", value = "性别", required = true),
                    @ApiImplicitParam(name = "pages", value = "第几页", required = true),
            }
    )
    public Map queryTeaBySex(String teaSex,int pages){
        return teacherService.queryTeaBySex(teaSex,pages);
    }

    /**
     *根据专业模糊查询
     */
    @GetMapping("/queryTeaByMajor")
    @ApiOperation(value = "根据专业模糊查询")
    @ResponseBody
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "teaMajor", value = "专业", required = true),
                    @ApiImplicitParam(name = "pages", value = "第几页", required = true),
            }
    )
    public Map queryTeaByMajor(String teaMajor,int pages){
        return teacherService.queryTeaByMajor(teaMajor,pages);
    }

    /**
     *根据学历模糊查询
     */
    @GetMapping("/queryTeaByEdu")
    @ApiOperation(value = "根据学历模糊查询")
    @ResponseBody
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "teaEducation", value = "学历", required = true),
                    @ApiImplicitParam(name = "pages", value = "第几页", required = true),
            }
    )
    public Map queryTeaByEdu(String teaEducation,int pages){
        return teacherService.queryTeaByEdu(teaEducation,pages);
    }

    /**
     *根据职称模糊查询
     */
    @GetMapping("/queryTeaByAcademic")
    @ApiOperation(value = "根据职称模糊查询")
    @ResponseBody
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "teaAcademic", value = "职称", required = true),
                    @ApiImplicitParam(name = "pages", value = "第几页", required = true),
            }
    )
    public Map queryTeaByAcademic(String teaAcademic,int pages){
        return teacherService.queryTeaByAcademic(teaAcademic,pages);
    }

    /**
     *根据毕业院校模糊查询
     */
    @GetMapping("/queryTeaBySchool")
    @ApiOperation(value = "根据毕业院校模糊查询")
    @ResponseBody
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "teaSchool", value = "毕业院校", required = true),
                    @ApiImplicitParam(name = "pages", value = "第几页", required = true),
            }
    )
    public Map queryTeaBySchool(String teaSchool,int pages){
        return teacherService.queryTeaBySchool(teaSchool,pages);
    }

    /**
     *根据所在院系模糊查询
     */
    @GetMapping("/queryTeaByFaculty")
    @ApiOperation(value = "根据所在院系模糊查询")
    @ResponseBody
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "teaFaculty", value = "所在院系", required = true),
                    @ApiImplicitParam(name = "pages", value = "第几页", required = true),
            }
    )
    public Map queryTeaByFaculty(String teaFaculty,int pages){
        return teacherService.queryTeaByFaculty(teaFaculty,pages);
    }

    /**
     * 模糊查询
     */
    @GetMapping("/queryConcat")
    @ApiOperation(value = "模糊查询")
    @ResponseBody
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "thing", value = "输入内容", required = true),
                    @ApiImplicitParam(name = "pages", value = "第几页", required = true),
            }
    )
    public Map queryConcat(String thing,int pages){
        return teacherService.queryConcat(thing,pages);
    }
}

 接着启动项目,输入http://localhost:8080/swagger-ui.html

 就可以看到接口了

----------------------------------------------我是完美的分割线呜啦啦------------------------------------------------

在使用thymeleaf时,我在方法return xxx;在页面返回的是xxx,经过查阅得知,@Controller +@ResponseBody= @RestController ,也就是

@Controller

+

@ResponseBody

==

@RestController

如果使用@RestController注解Controller,那么该Controller中的方法,就无法返回jsp,html页面,就是说如果在方法中return "xx",那么它只会返回"xx"的内容。

所以将controller层controller类上面的@RestController注解更换成@Controller,在方法上系上@ResponseBody注解即可返回正常的jsp,html页面。

详细实例可以参考springboot+springdata jpa+thymeleaf项目实战_雾喔的博客-CSDN博客

----------------------------------------------我是完美的分割线呜啦啦------------------------------------------------

个人总结:

最近在准备科目一,项目的话还是零零散散的接口,或者和另一位后端小伙伴抢抢接口,总而言之我还是觉得自己写的功能有点少,虽然有一些接口麻烦一点。。。

现在也在忙着小组的招新海报,现在卡了有一阵儿了,不知道数字怎么做,其他人也没什么方法,啊,争取今天把海报的文字啥的完成。

这几天着实是有点懒散了。就在刚刚,鼠标没电了,外面也下雨了,心情也随着鼠标电量暗淡了下去,努力想想,最近好像没什么能牵动我的心情了,啊,昨天测了一下体重,发现,我居然瘦了两斤,我的两斤肉啊,好不容易养的肉肉,就这样没了!

心情低落啊,太难受了,计划着未来几天调一下生物钟,晚上十点多就睡觉,谁也别想阻挡我早点睡觉的步伐!

争取把我的肉肉弄回来,胖胖的多可爱啊呜呜呜呜,咱就说,未来一周内,我要增肥两斤+。

你可能感兴趣的:(spring,boot,spring,java,后端)