发表于: 2019-10-12 19:44:11

1 955


1.完成的事情:

1)新建了一个spring boot工程,目录如下:

首先写了一个测试的接口:

package cn.jnshu.demo.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//测试
@RestController
public class HelloController {

@RequestMapping("/hello")
public String hello(){
return "Why so serious?";
   }
}

spring boot有内置的tomcat,默认端口是8080,打开网页可以成功返回数据:

2)然后就开始写公告管理后台部分的代码,先是后台公告管理的首页,我的理解就是把所有公告使用分页查询都查出来:

dao层代码:


@Mapper
@Component(value = "noticeMapper")
public interface NoticeMapper {

@Select("SELECT * FROM notice")
List<Notice> doFindAll();
}

controller:


@Controller
public class NoticeController {
@Autowired
   NoticeMapper noticeMapper;
   @RequestMapping("/noticeList")
public String doGetAll(Model model){
List<Notice> notices = noticeMapper.doFindAll();
       model.addAttribute("notices",notices);
       return "noticeList";
   }
}

先测一下能不能正常返回。。。

application.yml文件配置:

spring:
mvc:
view:
prefix: /WEB-INF/views/
suffix: .jsp
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
   url: jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
username: root
password: root
jpa:
hibernate:
ddl-auto: update
 mybatis:
mapper-locations: classpath:mapper/*.xml

点击运行,

启动成功了,然后打开网页看看:

404报错,返回的jsp有问题。。。网上搜索教程说使用spring-boot:run这个插件可以解决404的问题,

结果报错compile插件有问题。。。好像是jdk版本的问题。。。


2.明天的计划:

1)先把bug解决了,然后看一下动态查询这个功能怎么实现,好像同组的小伙伴也卡到动态查询这儿了。。。


返回列表 返回列表
评论

    分享到