发表于: 2019-11-04 23:45:42

1 993


今天完成的事情:

今天把方案评审过了,除了支付没做过。没什么难的地方。

把框架的一些要用的弄了下。

比如mybatis的自动生成工具,一开始一直和我之前用的不一样。没有生成动态SQL,后来发现是配置上的问题。

<context id="Mysql" targetRuntime="MyBatis3" defaultModelType="flat">

targetRuntime这里要等于 MyBatis3。


然后在tabel表标签那里要把不要的排除掉

<table tableName="study_like" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>


不过不知道为什么 ,没有动态查询。只有动态新增。

所以还是用以前自己写的吧,改一改就好了。

<select id="selectSelective" parameterType="com.happynewyear.admin.pojo.StudyLike" resultMap="BaseResultMap">
   select
<include refid="Base_Column_List"/>
   from study_like
<trim prefix="WHERE" prefixOverrides="AND|OR ">
       <if test="id != null ">ID=#{id}</if>
       <if test="type!= null ">and type= #{type}</if>
       <if test="bizId!= null ">and biz_id= #{bizId}</if>
       <if test="createBy !=null ">and create_by = #{createBy}</if>
       <if test="updateBy !=null ">and update_by = #{updateBy}</if>
       <if test="createAt !=null ">and create_at = #{createAt}</if>
       <if test="updateAt !=null ">and update_at = #{updateAt}</if>
   </trim>
</select>

这个是查询点赞的。即可以查列表,又可以查详细,不过……点赞好像用不上列表查询。


后面加了日志log4j2进去。先把自带的排除掉

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
   <exclusions>
       <exclusion>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-logging</artifactId>
       </exclusion>
   </exclusions>
</dependency>

再加上

<!--添加对日志系统的支持,采用最新的log4j2框架-->
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

然后,加上配置

log4j2.xml  这个太长了略。


在application.yml里添加

logging:
  config: classpath:log4j2.xml

然后使用,运行代码,然后报错。。。这里很晕,一直提示无法初始化配置文件,一开始以为是配置文件错了,但是做任务的时候就是用的这个啊。

而且上面也排除了自带的日志,,后面发现和其他的包冲突了。是个没用的。

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

后面询问了下组员,发现是没用的,删除,代码就跑起来了。。




遇到的问题:

一个是配置问题,一个是包冲突。



收获:

弄了个codemsg类。不知道正确不正确,能用就是

public class CodeMsg {
   private int code;
   private String msg;

   private CodeMsg(String msg,int code ) {
       this.code = code;
       this.msg = msg;
   }

   public int getCode() {
       return code;
   }

   public String getMsg() {
       return msg;
   }

   public static CodeMsg SUCCESS = new CodeMsg("请求成功",0);
   public static CodeMsg REQUEST_FAILED = new CodeMsg("请求失败",10000);



@GetMapping("/a/u/like")
public Map<String, Object> likeInsert(Integer tpye, Long bizId){
   HashMap<String, Object> result=new HashMap<>(16);
   try {
       log.info("用户ID为XX给{}类型ID为{}点赞",tpye,bizId);
       /*获取点赞人*/
       StudyLike studyLike=new StudyLike();
       studyLike.setType(tpye);
       studyLike.setBizId(bizId);
       List<StudyLike> studyLikes=studyLikeServer.selectSelective(studyLike);
       result.put("code",SUCCESS.getCode());
       result.put("msg",SUCCESS.getMsg());
       result.put("data",studyLikes);
       log.info("查到的点赞ID是{}",studyLikes.get(0).getId());
       return result;
   } catch (Exception e) {
       e.printStackTrace();
       e.getMessage();
       result.put("code",REQUEST_FAILED.getCode());
       result.put("msg",REQUEST_FAILED.getMsg());
       return result;
   }


请求参数随便添,这个是请求参数超出数据库位数所以报错。

{"msg":"请求失败","code":0,"data":[]}



返回列表 返回列表
评论

    分享到