发表于: 2018-01-19 23:33:32

1 585


今天做的事情:


       jar包修改,学习springboot整合SSM。


        做了个小demo,和之前做的区别最主要是:


         

@Mapper
public interface UserDao {

@Select("select * from user0120 where username = #{username}")
User findByName(@Param("username") String username);

   @Insert("insert into user0120(username,age) values (#{username},#{age})")
int insert(@Param("username") String username,@Param("age") Integer age);

}


          

         

     还有就是需要在配置文件中创建bean, 只要加了@Dao,@Service,自动可以扫描到。


     只不过,数据库中增加的是乱码。??这样的。


     找了很多解决方案,都不行。


      在application.properties中加了:

               


#避免中文乱码
server.tomcat.uri-encoding=UTF-8
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
spring.messages.encoding=UTF-8
character-set-server = utf8  


         找资料,都是这样的,看不懂。几句话都没,把代码一摆。


         


          2: 定时任务:


        在启动类里加 @EnableScheduling注解


         新建一个类,如下:

         

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


   @Component
   public class SchedulingTest {
private final Logger logger = LoggerFactory.getLogger(getClass());

       @Scheduled(cron = "0/5 * * * * ?") // 每5秒执行一次
       public void scheduler() {
logger.info(">>>>>>>>>>>>> scheduled test... ");
       }
}


         

       



遇到的问题:


            增加到数据库中文乱码,??



收获:


                学习了springboot。








       


返回列表 返回列表
评论

    分享到