Config:配置层,进行spring boot项目的一些配置。
package com.jacks.login.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@CrossOrigin
public class Config implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("login");
registry.addViewController("/r").setViewName("regist");
registry.addViewController("/s").setViewName("successful");
registry.addViewController("/m").setViewName("mianze");
registry.addViewController("/b").setViewName("blindbox");
registry.addViewController("/bt").setViewName("Blindboxtakeout");
registry.addViewController("/l").setViewName("lucky draw");
}
}
Controller层:管理层,负责与前端进行交互,接受前端请求并传入下一层。
package com.jacks.login.controller;
import com.jacks.login.pojo.Diary;
import com.jacks.login.service.Mainservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "main")
@CrossOrigin
public class MainController {
@Autowired
private Mainservice mainservice;
@PostMapping("/diary" )
public String diary(Diary diary){return mainservice.diary(diary);}
}
Service接口:与Controller层连接,其方法将在ServiceImpl层中实现。
package com.jacks.login.service;
import com.jacks.login.pojo.Diary;
public interface Mainservice {
String diary(Diary diary);
}
ServiceImpl层:实现具体的方法和进行逻辑处理等,处理完后将数据返回前端。
package com.jacks.login.service.impl;
import com.jacks.login.mapper.MainMapper;
import com.jacks.login.pojo.Diary;
import com.jacks.login.service.Mainservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class MainServiceImpl implements Mainservice {
@Autowired
MainMapper mainmapper;
@Override
public String diary(Diary diary){
String diary1=mainmapper.findByName(diary.getUsername());
if(diary1!=null)
return diary1;
else return "该用户未注册";
}
}
Mapper层:调用Mapper.xml中的sqL方法
package com.jacks.login.mapper;
import com.jacks.login.pojo.Diary;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
@Mapper
public interface MainMapper {
List<Diary> findAll();
String findByName(String diary);
}
Mapper.xml:写SQL语句的位置
版权声明:本文为weixin_63115481原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。