发表于: 2019-10-15 18:35:23
1 718
1.完成的事情:
1)解决了之前的bug,之前运行的时候报错404,然后使用spring boot run插件运行之后报编译器错误,在pom文件中添加了编译相关插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA8_HOME}/bin/javac</executable>
</configuration>
</plugin>
运行之后还是编译失败,然后在setting中:
这里显示java compile每次运行之后都会变成11,好像是因为最开始新建项目的时候顺手点了使用jdk1.11,导致后面怎么修改为1.8版本都会自动调整为1.11,于是就重新新建了工程,把java版本设置为1.8,再次编译就没问题了,但是运行之后网页还是报错,这应该是jsp文件写法有问题,然后就修改了代码,直接返回数据,不返回jsp:
@RestController
public class NoticeController {
@Autowired
NoticeMapper noticeMapper;
@RequestMapping("/noticeList")
public List doGetAll(Model model){
List<Notice> notices = noticeMapper.doGetAll();
model.addAttribute("notices",notices);
return notices;
}
运行之后,结果如下:
能跑通,查到所有数据;
2)然后是动态查询,代码如下:
mapper:
@Mapper
@Component(value = "noticeMapper")
public interface NoticeMapper {
List<Notice> doGetAll();
List<Notice> doGet(@Param("title")String title, @Param("time1") Long time1, @Param("time2")Long time2, @Param("status")int status);
}
mapper.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.jnshu.demo.mapper.NoticeMapper">
<select id="doGetAll" resultType="cn.jnshu.demo.pojo.Notice">
select * from notice
</select>
<select id="doGet" resultType="cn.jnshu.demo.pojo.Notice">
select * from notice
<where>
<if test="title != null and title != ''">
title like concat('%',#{title},'%')
</if>
<if test="status != null and status != ''">
and status =#{status}
</if>
<if test="time1 != null and time1 != ''">
and release_at >= #{time1}
</if>
<if test="time2 != null and time2 != ''">
and release_at <= #{time2}
</if>
</where>
</select>
</mapper>
controller:
@RequestMapping("/a/u/notice")
public List doGet(@Param("title")String title, @Param("time1") Long time1, @Param("time2")Long time2, @Param("status")int status,Model model){
List<Notice> notices = noticeMapper.doGet(title, time1, time2, status);
model.addAttribute("notices",notices);
return notices;
}
postman测试接口:
2.明天的计划:
1)这几天都是使用spring boot框架,明天开始学习spring cloud框架继续写公告后端的接口;
评论