The first springboot project

The company's recent projects use some components in springboot and springcloud. At first, they mainly write some business code, do not know how to configure it, etc. So recently, just have time to learn, record and summarize, and welcome to make corrections.

Start the first springboot project (eclipse+maven):

1. New maven project, add dependencies to pom
<!-- Parent Project -->

<!-- Add Dependency -->

2. New Startup Class
public class BowlApplication {
    public static void main(String[] args) {, args);
3. New Class, Control Layer
public class BowlController{
     * home page
     * @param mv
     * @return
    public ModelAndView index(ModelAndView mv) {;
        mv.addObject("id", "1");
        mv.addObject("name", "bowl");
        FoodInfo food = new FoodInfo();
        food.setRemark2("Test Attribute 1");
        mv.addObject("afood", food);
        return mv;
     * restful Style Passage
     * @param mv
     * @param id
     * @return
    public ModelAndView getFood(ModelAndView mv, @PathVariable("id") Integer id) {;
        FoodInfo food = bowlService.findFoodById(id);
        food.setRemark2("Test Attribute 2");
        mv.addObject("afood", food);
        return mv;

This is a test of your own, and if you just try to run the first springboot project first, you can remove the middle argument.

4. New Profile
#Start Port
  port: 55511

  file: ./logs/noodles.log

#Application Name
    name: asfood-noodles
#Environmental Science
    active: dev


5. New page (path: resources/templates/index.html)

There are many official page paths by default, so templates are used here.Page content, write a few, mainly for display.

Now start the main class, accessLocalhost:55511/noodles/indexShould be accessibleIndex.htmlPage.


Write your own exercise item code in: 

Tags: Java Spring SpringBoot Maven Attribute

Posted on Fri, 17 Jul 2020 11:28:51 -0400 by businessman332211